我将TF模型转换为ONNX,然后将ONNX模型转换为Caffe2。转换成功完成。但是,尝试从获得的模型进行加载和推断时,出现运行时错误。
这是我收到的错误。如何将“ is_true”属性添加到SpatialBN节点?
我浏览了pytorch回购,并看到了此问题,但是尚未解决。在此处的ONNX的代码库中,它is_test
为opset> = 7添加了属性,而我正在使用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 }
问题已解决。我正在使用自述文件中建议的命令行实用程序。但是,它使用过时的代码版本指向他们的教程。
命令行实用程序(使用进行安装pip install onnx-caffe2
)仍然具有_known_opset_version = 3
。这是导致错误。通过导入后,我通过PyTorch库中的Python API使用了转换实用程序后,
from caffe2.python.onnx.backend import Caffe2Backend as c2
我成功地对转换后的模型进行了推断。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句