This is the Python code I use to convert a mnist onnx model to the Caffe2 model:
import onnx
import caffe2.python.onnx.backend as onnx_caffe2_backend
# Load the ONNX ModelProto object. model is a standard Python protobuf object
model = onnx.load("mnist_model.onnx")
prepared_backend = onnx_caffe2_backend.prepare(model)
# extract the workspace and the model proto from the internal representation
c2_workspace = prepared_backend.workspace
c2_model = prepared_backend.predict_net
# Now import the caffe2 mobile exporter
from caffe2.python.predictor import mobile_exporter
# call the Export to get the predict_net, init_net. These nets are needed for running things on mobile
init_net, predict_net = mobile_exporter.Export(c2_workspace, c2_model, c2_model.external_input)
with open('init_net.pb', "wb") as fopen:
fopen.write(init_net.SerializeToString())
with open('predict_net.pb', "wb") as fopen:
fopen.write(predict_net.SerializeToString())
But when I run this code, the error occurs:
Traceback (most recent call last):
File “convertion.py”, line 20, in
init_net, predict_net = mobile_exporter.Export(c2_workspace, c2_model, c2_model.external_input)
File “/home/nico/anaconda3/lib/python3.7/site-packages/caffe2/python/predictor/mobile_exporter.py”, line 76, in Export
add_tensor(init_net, blob_name, blob)
File “/home/nico/anaconda3/lib/python3.7/site-packages/caffe2/python/predictor/mobile_exporter.py”, line 41, in add_tensor
kTypeNameMapper[blob.dtype],
KeyError: dtype(‘float64’)
Could you please help me?