onnx / onnx-caffe2

Caffe2 implementation of Open Neural Network Exchange (ONNX)
Other
165 stars 66 forks source link

Attribute error when preparing a model on MacOS #53

Open svohara opened 7 years ago

svohara commented 7 years ago

I have caffe2, onnx, onnx-caffe2 installed on a macbook (following the anaconda installation instructions).

I'm attempting to run the tutorial on converting a super-resolution model from pytorch to caffe2 via ONNX. The torch.onnx commands to save the model to onnx seem to work fine. However, when I try to use the saved model via the onnx-caffe2 backend's prepare method, I receive an attribute error, as shown below.

IIn [51]: model = onnx.load("/Users/ohara/data/models/super_resolution.onnx")

In [52]: prepared_backend = onnx_caffe2.backend.prepare(model)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-52-2fbcb732bd1d> in <module>()
----> 1 prepared_backend = onnx_caffe2.backend.prepare(model)

/Users/ohara/anaconda3/envs/python2/lib/python2.7/site-packages/onnx_caffe2/backend.pyc in prepare(cls, predict_graph, device, init_graph, **kwargs)
    309                 init_net = caffe2_pb2.NetDef()
    310 
--> 311             predict_net, _ = cls._onnx_graph_to_caffe2_net(predict_graph)
    312             predict_net.device_option.CopyFrom(get_device_option(device))
    313 

/Users/ohara/anaconda3/envs/python2/lib/python2.7/site-packages/onnx_caffe2/backend.pyc in _onnx_graph_to_caffe2_net(cls, graph_def)
    423 
    424         net_def = caffe2_pb2.NetDef()
--> 425         net_def.name = graph_def.name
    426 
    427         # environment from ONNX name to Caffe2 name

AttributeError: 'ModelProto' object has no attribute 'name'
bddppq commented 7 years ago

Looks like that your onnx and onnx-caffe2 are directly pulled from conda? There have been some updates happened recently, please follow instructions on github front page to install them from source.