onnx / tutorials

Tutorials for creating and using ONNX models
Apache License 2.0
3.39k stars 630 forks source link

Caffe2 to ONNX tutorial assertion fails - re.match('GivenTensor.*Fill', op.type) #8

Open MrGeva opened 6 years ago

MrGeva commented 6 years ago

I followed the instructions on Caffe2OnnxExport.ipynb on Ubuntu16.04, ran the following command line: convert-caffe2-to-onnx /home/eran/Downloads/squeezenet_caffe2/predict_net.pb --caffe2-init-net /home/eran/Downloads/squeezenet_caffe2/exec_net.pb --value-info '{"data": [1, [1, 3, 224, 224]]}' -o sqeezenet.onnx --caffe2-net-name sqeezenet

Got the following error: Traceback (most recent call last): File "/usr/local/bin/convert-caffe2-to-onnx", line 11, in <module> load_entry_point('onnx-caffe2==1.0.0', 'console_scripts', 'convert-caffe2-to-onnx')() File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/bin/conversion.py", line 61, in caffe2_to_onnx value_info=value_info) File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 517, in caffe2_net_to_onnx_model model = make_model(cls.caffe2_net_to_onnx_graph(*args, **kwargs)) File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 357, in caffe2_net_to_onnx_graph cls._ssa_rewrite(predict_net, init_net, value_info) File "/usr/local/lib/python2.7/dist-packages/onnx_caffe2/frontend.py", line 492, in _ssa_rewrite assert re.match('GivenTensor.*Fill', op.type) AssertionError

@jamesr66a @bddppq

zyw400 commented 6 years ago

Same here.

The op.type is: [u'GivenTensorFill', ..., u'ConstantFill'] for a model I created.

The last one "ConstantFill" will generate assertion error.

houseroad commented 6 years ago

https://github.com/caffe2/caffe2/pull/2058 should fix the problem.

kukramer commented 6 years ago

I am also having an issue converting a Caffe model -> Caffe2 -> ONNX.

I use "python -m caffe2.python.caffe_translator That works fine; but "convert-caffe2-to-onnx" fails doing a assert on last layer which is a Sigmoid using "ConstantFill".

I believe "ConstantFill" should be valid?

houseroad commented 6 years ago

@kukramer could you paste the converted Caffe2 model, so I can reproduce the problem?

kukramer commented 6 years ago

I can not provide the network that is having the issue; I will need to make a smaller one that demonstrates the issue. I will add once I have;

In meantime sigmoid is the layer that is having a problem; it does not require any parameters/ tensor's return 1. / (1. + exp(-x));

Caffe2 Layer that has problem

op { input: "fc" output: "loss" type: "Sigmoid" }

==========================================

c2_init_net_proto.op[14] output: "data" name: "" type: "ConstantFill" arg { name: "shape" ints: 1 }

eduardolcordeiro commented 6 years ago

I am currently encountering this problem when importing networks from here : http://places.csail.mit.edu/downloadCNN.html

All the networks for place205 give this errors, but I managed to convert the placed 365 network, alltought I did this just to see if it was a general problem or not.

I have converted them from caffe to caffe2 sucessfully (I think).

Any idea if this issue has been merged?

I am running ubuntu 16.04, caffe2 installed using Anaconda.

@houseroad

cayleyhamilton commented 5 years ago

Any update on this? I'm having this problem when converting caffe2 pbs to ONNX image @houseroad

anilsathyan7 commented 5 years ago

We are facing similar issue...

assert re.match('GivenTensor.*Fill', op.type), "type is {}, \n{}".format(op.type, op)
AssertionError: type is ConstantFill, 
output: "data"
name: ""
type: "ConstantFill"
arg {
  name: "shape"
  ints: 1
}

(Using conda python 2.7) The error occurs during caffe2 to onnx conversion.We tried using shell command and python script as shown in https://github.com/onnx/tutorials/blob/master/tutorials/Caffe2OnnxExport.ipynb. How can we resolve this problem? Here is the pbtxt obatined from conversion of caffe model to caffe2 using caff_to_caffe2 converter. File: predict_net_pbtxt.txt

Joeywzr commented 5 years ago

Similar problem. I have converted the ONNX models to Caffe2 models using convert-onnx-to-caffe2 and I got predict_net.pb and init_net.pb. However, when I try to convert the Caffe2 models back to ONNX models, I got the following error message:

Traceback (most recent call last):
  File "/home/memo/.cache/bazel/_bazel_memo/74d5227f86e9c48dd23510319ac3d793/external/org_pocoo_werkzeug/werkzeug/serving.py", line 205, in run_wsgi
    execute(self.server.app)
  File "/home/memo/.cache/bazel/_bazel_memo/74d5227f86e9c48dd23510319ac3d793/external/org_pocoo_werkzeug/werkzeug/serving.py", line 193, in execute
    application_iter = app(environ, start_response)
  File "/media/memo/Mess/tensorboardplugins-master/tensorboard/backend/application.py", line 349, in __call__
    return self.data_applications[clean_path](environ, start_response)
  File "/home/memo/.cache/bazel/_bazel_memo/74d5227f86e9c48dd23510319ac3d793/external/org_pocoo_werkzeug/werkzeug/wrappers.py", line 291, in application
    return f(*args[:-2] + (request,))(*args[-2:])
  File "/media/memo/Mess/tensorboardplugins-master/tensorboard/plugins/convert/convert_plugin.py", line 159, in convert_model
    value_info=value_info)
  File "/home/memo/.local/lib/python3.6/site-packages/caffe2/python/onnx/frontend.py", line 350, in caffe2_net_to_onnx_model
    model = make_model(cls.caffe2_net_to_onnx_graph(*args, **kwargs),
  File "/home/memo/.local/lib/python3.6/site-packages/caffe2/python/onnx/frontend.py", line 195, in caffe2_net_to_onnx_graph
    cls._ssa_rewrite(predict_net, init_net, value_info)
  File "/home/memo/.local/lib/python3.6/site-packages/caffe2/python/onnx/frontend.py", line 320, in _ssa_rewrite
    assert re.match('GivenTensor.*Fill', op.type), "type is {}, \n{}".format(op.type, op)
AssertionError: type is ExpandDims, 
input: "497"
output: "499"
name: ""
type: "ExpandDims"
arg {
  name: "dims"
  ints: 0
}

Environment:

PyTorch version: 1.2.0
Is debug build: No
CUDA used to build PyTorch: 10.0.130

OS: Deepin 15.11
GCC version: (Debian 4.8.5-4) 4.8.5
CMake version: version 3.11.2

Python version: 3.6
Is CUDA available: No
CUDA runtime version: 8.0.61
GPU models and configuration: GPU 0: GeForce GTX 970M
Nvidia driver version: 390.67
cuDNN version: Could not collect

Versions of relevant libraries:
[pip3] numpy==1.16.2
[pip3] torch==1.2.0
[conda] torch                     1.1.0                     <pip>