1
model = VGGish()  # vgg model class
model.train(False)
x = torch.randn(10, 1, 64, 96, requires_grad=True)
# Export the model
torch_out = torch.onnx._export(model,             # model being run`enter code here`
                               x,                       # model input (or a tuple for multiple inputs)
                               "super_resolution.onnx", # where to save the model (can be a file or file-like object)
                               export_params=True)      # store the trained parameter weights inside the model file

model = onnx.load("modelsVGGish_conv.onnx")
onnx.checker.check_model(model)
onnx.helper.printable_graph(model.graph)
rep = backend.prepare(model, device="CPU") # or "CPU"

当程序运行到这段代码

rep = backend.prepare(model, device="CPU") # or "CPU"

发生错误:

Traceback (most recent call last):
  File "C:/Users/xxx/Desktop/python/新建文件夹/onnx_to_caffe2.py", line 159, in <module>
    rep = backend.prepare(model, device="CPU") # or "CPU"
  File "D:\environment\Anaconda\lib\site-packages\caffe2\python\onnx\backend.py", line 713, in prepare
    init_net, predict_net = cls._onnx_model_to_caffe2_net(model, device, opset_version, False)
  File "D:\environment\Anaconda\lib\site-packages\caffe2\python\onnx\backend.py", line 876, in _onnx_model_to_caffe2_net
    onnx_model = onnx.utils.polish_model(onnx_model)
  File "D:\environment\Anaconda\lib\site-packages\onnx\utils.py", line 21, in polish_model
    model = onnx.optimizer.optimize(model)
  File "D:\environment\Anaconda\lib\site-packages\onnx\optimizer.py", line 55, in optimize
    optimized_model_str = C.optimize(model_str, passes)
IndexError: invalid unordered_map<K, T> key

简直让我抓狂!</p>

任何人都可以帮助我吗?

4

1 回答 1

-1

不幸的是,如果没有实际模型,就很难调试它。然而,在 ONNX 模型动物园里有 4 个已经转换的ONNX VGG 模型。

请随意使用开箱即用的 ONNX 解决方案,或将您的疑虑作为问题发布到 github 上以进行进一步调试。

于 2020-02-05T19:58:41.317 回答