欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > onnx基本概念

onnx基本概念

2024/10/24 17:28:23 来源:https://blog.csdn.net/jiaochong11/article/details/139721801  浏览:    关键词:onnx基本概念

onnx基本概念

参考

文章目录

  • onnx基本概念
    • Input, Output, Node, Initializer, Attributes
    • Serialization with protobuf
    • 元数据
    • List of available operators and domains
    • 支持的类型
    • Opset版本
    • Subgraphs, tests and loops
    • Extensibility
    • Functions
    • Shape (and Type) Inference
    • tools

ONNX可以类比为专注于数学函数的一个专用变成语言,在这个语言中,定义了机器学习推理过程中所必要的操作。比如,一个线性回归可以描述为:

def onnx_linear_regressor(X):"ONNX code for a linear regression"return onnx.Add(onnx.MatMul(X, coefficients), bias)

也可以使用ONNX图进行表示。

在这里插入图片描述
ONNX的目标是提供一种能够被任意机器学习框架实用的通用语言。利用ONNX,可以独立于构建模型的学习框架实现生产环境的部署。ONNX也实现了以一个运行时ONNXRuntime,但是主要目的是理解和调试以及转换工具,并不是用于生产环境,因为性能不是其目标。

Input, Output, Node, Initializer, Attributes

  • 一个算子,最基本的是包含输入和输出。
  • Node,是计算图的节点
  • initializer是指输入中不变的常量。
  • Attributes是指算子的参数

Serialization with protobuf

利用protobuf实现序列化

元数据

  • doc_string: Human-readable documentation for this model.
    Markdown is allowed.

  • domain: A reverse-DNS name to indicate the model namespace or domain,
    for example, ‘org.onnx’

  • metadata_props: Named metadata as dictionary map<string,string>,
    (values, keys) should be distinct.

  • model_author: A comma-separated list of names,
    The personal name of the author(s) of the model, and/or their organizations.

  • model_license: The well-known name or URL of the license
    under which the model is made available.

  • model_version: The version of the model itself, encoded in an integer.

  • producer_name: The name of the tool used to generate the model.

  • producer_version: The version of the generating tool.

  • training_info: An optional extension that contains

List of available operators and domains

算子列表

算子的域名主要来自ai.onnx以及ai.onnx.ml,同时支持可扩展性,定义自己的算子。

支持的类型

ONNX主要是优化数值计算的tensor,包含三大元素

  • 类型
  • 形状(维度)
  • 连续的存储空间

Opset版本

每个onnx图都绑定一个Opset版本

Subgraphs, tests and loops

ONNX实现了条件判断和训练,这些模块将别的子图作为属性。这些结构通常慢且复杂,应避免使用。

Extensibility

可扩展性,每一个节点都有 type, a name, named inputs and outputs, and attributes. 只要一个节点具有上述要素,就可以添加到计算图中.

Functions

Functions是一种扩展ONNX规范的方法,用于描述一系列算子的组合,方便复用。

Shape (and Type) Inference

ONNX不必要明确的输入输出的shape,但是可以加速推理。

tools

netron是一个很好的可视化工具

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com