qfgaohao / pytorch-ssd

MobileNetV1, MobileNetV2, VGG based SSD/SSD-lite implementation in Pytorch 1.0 / Pytorch 0.4. Out-of-box support for retraining on Open Images dataset. ONNX and Caffe2 support. Experiment Ideas like CoordConv.
https://medium.com/@smallfishbigsea/understand-ssd-and-implement-your-own-caa3232cd6ad
MIT License
1.4k stars 534 forks source link

Error converting ONNX to caffe2 #37

Open rracinskij opened 5 years ago

rracinskij commented 5 years ago

Hi,

the conversion of the model to caffe2 via ONNX does not work with Pytorch 1.0.1. The initial script converts the model to ONNX, but the conversion to caffe2 fails, as init_net, predict_net = c2.onnx_graph_to_caffe2_net(model) results in the Segmentation fault (core dumped) error.

I aslo tried to adapt a script from [https://pytorch.org/tutorials/advanced/super_resolution_with_caffe2.html]() :

import onnx
import caffe2.python.onnx.backend as onnx_caffe2_backend
from caffe2.python.predictor import mobile_exporter

model = onnx.load('models/mb1-ssd.onnx')
prepared_backend = onnx_caffe2_backend.prepare(model)
c2_workspace = prepared_backend.workspace
c2_model = prepared_backend.predict_net
init_net, predict_net = mobile_exporter.Export(c2_workspace, c2_model, c2_model.external_input)

but it also fails:

...anaconda3/lib/python3.6/site-packages/caffe2/python/predictor/mobile_exporter.py", line 41, in add_tensor
    kTypeNameMapper[blob.dtype],
KeyError: dtype('float64')
qfgaohao commented 5 years ago

Caffe2 is harder to use in the latest versions. I will move it to pytorch1.0 c++ backend if i have time.