[翻译] OpenVINO mo_onnx.py

--input_model INPUT_MODEL, -w INPUT_MODEL, -m INPUT_MODEL
    Tensorflow*: a file with a pre-trained model (binary or text .pb file after freezing). Caffe*: a model proto file with model weights
	Tensorflow *:具有预训练模型的文件(冻结后的二进制或文本.pb文件)。 Caffe *:具有模型权重的模型原型文件

--model_name MODEL_NAME, -n MODEL_NAME
	Model_name parameter passed to the final create_ir transform. This parameter is used to name a network in a generated IR and output .xml/.bin files.
	将Model_name参数传递给最终的create_ir转换。 此参数用于在生成的IR中命名网络并输出.xml / .bin文件。

--output_dir OUTPUT_DIR, -o OUTPUT_DIR
   Directory that stores the generated IR. By default, it  is the directory from where the Model Optimizer is launched.
   存储生成的IR的目录。 默认情况下,它是启动模型优化器的目录。

--input_shape INPUT_SHAPE
        Input shape(s) that should be fed to an input node(s) of the model. Shape is defined as a comma-separated  list of integer numbers enclosed in parentheses or  square brackets, for example [1,3,227,227] or (1,227,227,3), where the order of dimensions depends  on the framework input layout of the model. For  example, [N,C,H,W] is used for Caffe* models and  [N,H,W,C] for TensorFlow* models. Model Optimizer performs necessary transformations to convert the shape to the layout required by Inference Engine (N,C,H,W). The shape should not contain undefined  dimensions (? or -1) and should fit the dimensions defined in the input operation of the graph. If there  are multiple inputs in the model, --input_shape should contain definition of shape for each input separated  by a comma, for example: [1,3,227,227],[2,4] for a  model with two inputs with 4D and 2D shapes. Alternatively, specify shapes with the --input option.
    应输入模型的输入节点的输入形状。 形状定义为用逗号分隔的用括号或方括号括起来的整数列表,例如[1,3,227,227]或(1,227,227,3),其中尺寸顺序取决于模型的框架输入布局。 例如,[N,C,H,W]用于Caffe *模型,[N,H,W,C]用于TensorFlow *模型。 模型优化器执行必要的转换,以将形状转换为推理引擎所需的布局(N,C,H,W)。 形状不应包含未定义的尺寸(?或-1),并且应适合在图形的输入操作中定义的尺寸。 如果模型中有多个输入,则--input_shape应包含每个输入的形状定义,并用逗号分隔,例如:[1,3,227,227][2,4]对于具有两个4D和2D形状的输入的模型 。 或者,使用--input选项指定形状。
    
--scale SCALE, -s SCALE
	All input values coming from original network inputs  will be divided by this value. When a list of inputs  is overridden by the --input parameter, this scale is  not applied for any input that does not match with the original input of the model.
	来自原始网络输入的所有输入值都将被该值除。 当输入列表被--input参数覆盖时,该比例不适用于与模型原始输入不匹配的任何输入。

--reverse_input_channels
 	Switch the input channels order from RGB to BGR (or vice versa). Applied to original inputs of the model  if and only if a number of channels equals 3. Applied  after application of --mean_values and --scale_values  options, so numbers in --mean_values and  --scale_values go in the order of channels used in the  original model.
 	将输入通道顺序从RGB切换到BGR(反之亦然)。 当且仅当通道数等于3时,才应用于模型的原始输入。在应用--mean_values和--scale_values选项后应用,因此--mean_values和--scale_values中的数字按通道中使用的通道顺序排列 原始模型。

--log_level 		  {CRITICAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}


--input INPUT         
	Quoted list of comma-separated input nodes names with shapes, data types, and values for freezing. The shape  and value are specified as space-separated lists. The  data type of input node is specified in braces and can have one of the values: f64 (float64), f32 (float32),   f16 (float16), i64 (int64), i32 (int32), u8 (uint8), boolean. For example, use the following format to set   input port 0 of the node `node_name1` with the shape [3 4] as an input node and freeze output port 1 of the node `node_name2` with the value [20 15] of the int32 type and shape [2]: "0:node_name1[3 4],node_name2:1[2]{i32}->[20 15]".
	用逗号分隔的输入节点名称(带形状,数据类型和冻结值)的带引号的列表。 形状和值指定为以空格分隔的列表。 输入节点的数据类型以大括号指定,并且可以具有以下值之一:f64(float64),f32(float32),f16(float16),i64(int64),i32(int32),u8(uint8),布尔值。 例如,使用以下格式将形状为[3 4]的节点'node_name1'的输入端口0设置为输入节点,并冻结节点int32的值[20 15]的节点`node_name2`的输出端口1。 类型和形状[2]:“ 0:node_name1 [3 4],node_name2:1 [2] {i32}-> [20 15]”。

--output OUTPUT       
	The name of the output operation of the model. For TensorFlow*, do not add :0 to this name.
	模型的输出操作的名称。 对于TensorFlow *,请勿在该名称上添加:0。

--mean_values MEAN_VALUES, -ms MEAN_VALUES
	Mean values to be used for the input image per channel. Values to be provided in the (R,G,B) or  [R,G,B] format. Can be defined for desired input of the model, for example: "--mean_values  data[255,255,255],info[255,255,255]". The exact  meaning and order of channels depend on how the original model was trained.
     每个通道用于输入图像的平均值。 以(R,G,B)或[R,G,B]格式提供的值。 可以为模型的所需输入定义,例如:“-mean_values data [255,255,255],info [255,255,255]”。 通道的确切含义和顺序取决于原始模型的训练方式。

--scale_values SCALE_VALUES
	Scale values to be used for the input image per  channel. Values are provided in the (R,G,B) or [R,G,B]  format. Can be defined for desired input of the model, for example: "--scale_values data[255,255,255],info[255,255,255]". The exact  meaning and order of channels depend on how the original model was trained.
	每个通道用于输入图像的比例值。 值以(R,G,B)或[R,G,B]格式提供。 可以为模型的所需输入定义,例如:“-scale_values data [255,255,255],info [255,255,255]”。 通道的确切含义和顺序取决于原始模型的训练方式。
      
--data_type {FP16,FP32,half,float}
	Data type for all intermediate tensors and weights. If  original model is in FP32 and --data_type=FP16 is specified, all model weights and biases are quantized  to FP16.
	所有中间张量和权重的数据类型。 如果原始模型位于FP32中,并且指定了--data_type = FP16,则所有模型权重和偏差都将量化为FP16。
       
--disable_fusing      
	Turn off fusing of linear operations to Convolution
	关闭将线性运算与卷积的融合

--disable_resnet_optimization
    Turn off resnet optimization
    关闭Resnet优化

--finegrain_fusing FINEGRAIN_FUSING
    Regex for layers/operations that won't be fused. Example: --finegrain_fusing Convolution1,.*Scale.*
    正则表达式用于不会融合的层/操作。 示例:--finegrain_fusing卷积1,。* Scale。*
    
--disable_gfusing 
  Turn off fusing of grouped convolutions
  关闭分组卷积的融合
  
--enable_concat_optimization
    Turn on Concat optimization.
    打开Concat优化。
    
--move_to_preprocess  
  Move mean values to IR preprocess section
  将平均值移至IR预处理部分
  
--extensions EXTENSIONS
     Directory or a comma separated list of directories with extensions. To disable all extensions including
those that are placed at the default location, pass an empty string.
	目录或以逗号分隔的带有扩展名的目录列表。 要禁用所有扩展名,包括放置在默认位置的扩展名,请传递一个空字符串。
	
--batch BATCH, -b BATCH
     Input batch size
     输入批量
     
--version  
	Version of Model Optimizer
	模型优化器的版本
	
--silent     
	Prevent any output messages except those that correspond to log level equals ERROR, that can be set with the following option: --log_level. By default,log level is already ERROR.
	防止使用与以下日志选项对应的输出消息(与日志级别对应的消息等于ERROR除外)进行设置:--log_level。 默认情况下,日志级别已为ERROR。
	
--freeze_placeholder_with_value 		 fREEZE_PLACEHOLDER_WITH_VALUE Replaces input layer with constant node with provided value, for example: "node_name->True". It will be DEPRECATED in future releases. Use --input option to specify a value for freezing.
	FREEZE_PLACEHOLDER_WITH_VALUE用具有提供值的恒定节点替换输入层,例如:“ node_name-> True”。 在将来的版本中将不再使用。 使用--input选项指定冻结值。
	
--generate_deprecated_IR_V7
    Force to generate deprecated IR V7 with layers from old IR specification.
    强制生成具有旧IR规范中的图层的已弃用的IR V7。
    
--static_shape  
	Enables IR generation for fixed input shape (folding `ShapeOf` operations and shape-calculating sub-graphs to `Constant`). Changing model input shape using the Inference Engine API in runtime may fail for such an IR.
	为固定的输入形状启用IR生成(将“ ShapeOf”操作和形状计算子图折叠为“ Constant”)。 对于此类IR,在运行时使用Inference Engine API更改模型输入形状可能会失败
	
--keep_shape_ops   
  The option is ignored. Expected behavior is enabled by default.
  该选项被忽略。 默认情况下启用预期行为。

--disable_weights_compression
      Disable compression and store weights with original precision.
      禁用压缩并以原始精度存储重量
      
--progress      
  Enable model conversion progress display.
  启用模型转换进度显示。
  
--stream_output  
   Switch model conversion progress display to a multiline mode.
   将模型转换进度显示切换到多行模式。

--transformations_config 
	TRANSFORMATIONS_CONFIG Use the configuration file with transformations description.
	TRANSFORMATIONS_CONFIG将配置文件与转换说明一起使用。
<think>好的,我现在要解决用户的问题:OpenCV的DNN模块读取ONNX模型文件时出现错误,提示无法读取best.onnx,使用的OpenCV版本是4.11.0。用户还提到了OpenVINO的部署过程,可能相关。 首先,我需要分析可能的原因。根据常见的OpenCV DNN问题,可能有以下几个原因: 1. **ONNX模型版本兼容性问题**:不同版本的OpenCV支持的ONNX opset版本可能不同。例如,较新的模型可能需要更高版本的OpenCV或特定的opset。用户使用的OpenCV 4.11.0可能不支持模型使用的opset版本。 2. **模型导出问题**:在导出ONNX模型时,可能存在不支持的层或操作,或者导出过程中出现错误,导致模型文件损坏或不完整。 3. **依赖项缺失**:OpenCV的DNN模块需要依赖Protobuf来解析ONNX模型,如果Protobuf版本不兼容或安装有问题,可能导致读取失败。 4. **OpenCV编译选项**:用户可能使用的OpenCV版本未正确编译DNN模块或缺少ONNX支持,比如没有启用Protobuf或缺少必要的依赖库。 接下来,我需要逐一排查这些可能性: **第一步:检查ONNX模型的有效性**。用户可以使用ONNX Runtime或Netron工具来验证模型是否能被正确加载。如果模型本身有问题,可能需要重新导出。例如,使用PyTorch导出时,确保使用`torch.onnx.export`的正确参数,如指定opset_version=12或更低,以兼容旧版OpenCV。 **第二步:确认OpenCV版本与ONNX opset兼容性**。OpenCV 4.11.0可能支持到opset 12或13。如果模型使用了更高版本的opset,需要降级导出。例如,在导出模型时添加参数`opset_version=12`。 **第三步:检查Protobuf版本**。OpenCV DNN对Protobuf版本敏感,可能需要3.x版本。如果用户环境中的Protobuf是4.x,可能会有兼容性问题。建议降级到3.20.x版本。 **第四步:重新编译OpenCV**。如果预编译的OpenCV缺少ONNX支持,用户可能需要从源码编译,确保启用BUILD_opencv_dnn和Protobuf,并正确配置路径。 此外,用户提到了OpenVINO,可能需要考虑使用OpenVINO的推理引擎来加载模型,这通常对ONNX的支持更好。例如,使用OpenVINO的`InferenceEngine`读取ONNX模型,或者将ONNX换为IR格式。 最后,建议用户提供具体的错误信息,如堆栈跟踪或日志,以便更精准地定位问题。如果问题依旧,尝试简化模型结构或使用OpenCV的示例模型测试,确定是否为模型特定问题。</think>针对OpenCV DNN模块读取ONNX模型文件报错的问题,以下是分步骤解决方案: --- ### 一、检查ONNX模型有效性 1. **使用ONNX Runtime验证模型** 安装ONNX Runtime库后运行以下代码: ```python import onnxruntime as ort ort_session = ort.InferenceSession("best.onnx") # 若报错则模型存在问题 ``` 若提示`opset版本不支持`,需重新导出模型时指定兼容的opset版本,例如: ```python torch.onnx.export(..., opset_version=12) # 推荐opset≤12 ``` 2. **用Netron可视化模型结构** 访问[Netron官网](https://netron.app/)上传模型,检查是否存在非常规算子(如自定义层)[^1]。 --- ### 二、确认OpenCV版本与ONNX兼容性 - **OpenCV 4.11.0对ONNX的支持限制** 该版本支持的ONNX opset通常≤13,若模型使用更高版本需降级导出。通过以下命令查看模型opset: ```python import onnx model = onnx.load("best.onnx") print(model.opset_import[0].version) ``` --- ### 三、修复Protobuf依赖问题 1. **检查Protobuf版本** 运行以下命令查看版本: ```bash pip show protobuf ``` **建议使用Protobuf 3.20.x**,若版本≥4.x需降级: ```bash pip install protobuf==3.20.3 ``` 2. **清理Protobuf缓存** 删除`~/.cache/protobuf`目录(Linux/Mac)或`C:\Users\<用户>\.cache\protobuf`(Windows)。 --- ### 四、重新编译OpenCV(可选) 若预编译版本缺少DNN支持,需从源码编译: ```bash git clone https://github.com/opencv/opencv.git cd opencv && git checkout 4.11.0 # 切换至对应版本 mkdir build && cd build cmake -DOPENCV_DNN_ONNX=ON -DBUILD_PROTOBUF=OFF -DPROTOBUF_UPDATE_FILES=ON .. make -j4 sudo make install ``` --- ### 五、使用OpenVINO替代方案 若问题仍未解决,可通过OpenVINO优化模型并推理: 1. **ONNX为IR格式** ```bash mo --input_model best.onnx --output_dir ir_output ``` 2. **使用OpenVINO加载模型** ```python from openvino.runtime import Core core = Core() model = core.read_model("ir_output/best.xml") compiled_model = core.compile_model(model, "CPU") ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DYF-AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值