chuanqi305 / MobileNet-SSD

Caffe implementation of Google MobileNet SSD detection network, with pretrained weights on VOC0712 and mAP=0.727.
MIT License
2k stars 1.18k forks source link

convert .pth to ONXX #173

Closed zhoujinhai closed 4 years ago

zhoujinhai commented 4 years ago

I have trained the pytorch model.pth on my dataset, then, I use the convert_to_caffe2_models.py to convert ONXX model, but it raise an error like this:

Traceback (most recent call last):
  File "convert_to_caffe2_models.py", line 50, in <module>
    torch.onnx.export(net, dummy_input, model_path, verbose=False, output_names=['scores', 'boxes'])
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/__init__.py", line 25, in export
    return utils.export(*args, **kwargs)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/utils.py", line 131, in export
    strip_doc_string=strip_doc_string)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/utils.py", line 363, in _export
    _retain_param_name, do_constant_folding)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/utils.py", line 278, in _model_to_graph
    _disable_torch_constant_prop=_disable_torch_constant_prop)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/utils.py", line 188, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/__init__.py", line 50, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/utils.py", line 589, in _run_symbolic_function
    return fn(g, *inputs, **attrs)
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/symbolic.py", line 130, in wrapper
    args = [_parse_arg(arg, arg_desc) for arg, arg_desc in zip(args, arg_descriptors)]
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/symbolic.py", line 130, in <listcomp>
    args = [_parse_arg(arg, arg_desc) for arg, arg_desc in zip(args, arg_descriptors)]
  File "/home/tsd/.local/lib/python3.6/site-packages/torch/onnx/symbolic.py", line 90, in _parse_arg
    raise RuntimeError("Failed to export an ONNX attribute, "
RuntimeError: Failed to export an ONNX attribute, since it's not constant, please try to make things (e.g., kernel size) static if possible