【问题标题】:Issue when converting ONNX model to Caffe2将 ONNX 模型转换为 Caffe2 时的问题
【发布时间】:2020-11-23 17:15:21
【问题描述】:

我将一个 TF 模型转换为 ONNX,然后将 ONNX 模型转换为 Caffe2。转换成功发生。但是,在尝试从获得的模型中加载和推断时,我遇到了运行时错误。

这是我收到的错误。如何将属性“is_true”添加到 SpatialBN 节点?

我浏览了 pytorch repo 并看到了这个 issue,但是,它尚未解决。 在 ONNX here 的代码库中,它为 opset >=7 添加了is_test 属性,我使用的是 8。但是,它仍然给出错误。

[W common_gpu.cc:35] Insufficient cuda driver. Cannot use cuda.
[W init.h:137] Caffe2 GlobalInit should be run before any other API calls.
[W init.h:137] Caffe2 GlobalInit should be run before any other API calls.
[W predictor_config.cc:90] Caffe2 is compiled without optimization passes.
[E operator_schema.cc:101] Argument 'is_test' is required for Operator 'SpatialBN'.
Traceback (most recent call last):
  File "main.py", line 91, in <module>
    test_caffe("mod-caffe-net.pb", "mod-caffe-init-net.pb", "../data/mouth")
  File "main.py", line 70, in test_caffe
    predictor = workspace.Predictor(param_values, model_net)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/caffe2/python/workspace.py", line 187, in Predictor
    return C.Predictor(StringifyProto(init_net), StringifyProto(predict_net))
RuntimeError: [enforce fail at operator.cc:199] schema->Verify(operator_def). Operator def did not pass schema checking: input: "conv1/Relu:0" input: "batchNorm1/gamma/read/_1__cf__1:0" input: "batchNorm1/beta/read/_0__cf__0:0" input: "batchNorm2/moving_mean/read/_6__cf__6:0" input: "batchNorm1/moving_variance/read/_3__cf__3:0" output: "batchNorm1/FusedBatchNorm:0" name: "batchNorm1/FusedBatchNorm" type: "SpatialBN" arg { name: "epsilon" f: 0.001 } device_option { device_type: 0 device_id: 0 }

【问题讨论】:

  • 有什么理由不使用较新的 opset,例如 12?
  • 这是默认设置,因此,坚持这一点。我尝试了 9 和 10。但是,我面临一个不同的错误。 op Conv: Source for input conv1/kernel/read/_17__cf__17:0 is unknown for net tf2onnx, operator input: "conv1/BiasAdd__8:0"

标签: inference onnx caffe2 onnxruntime


【解决方案1】:

问题已解决。我正在使用他们README 上建议的命令行实用程序。但是,它指向了他们在已弃用的code 版本中的教程。

命令行实用程序(使用pip install onnx-caffe2 安装)仍然具有_known_opset_version = 3。这是导致错误的原因。在我通过导入 PyTorch 库中的 Python API 使用转换实用程序后,

from caffe2.python.onnx.backend import Caffe2Backend as c2

我成功地在转换后的模型上运行推理。

【讨论】:

  • 很好,您找到了解决方案。您可以接受自己的答案,因此该问题不会被列为“有效”。
猜你喜欢
  • 2019-12-09
  • 2020-03-31
  • 2020-02-12
  • 2022-10-13
  • 2023-01-31
  • 2018-10-05
  • 2018-11-25
  • 2019-11-10
  • 2022-09-27
相关资源
最近更新 更多