htshinichi / caffe-onnx

caffe model convert to onnx model
MIT License
175 stars 43 forks source link

MobileNet (SSD) #8

Closed Yrij-Zhavoronkov closed 4 years ago

Yrij-Zhavoronkov commented 4 years ago

I try to convert MobileNet tet to onnx but its take me: Traceback (most recent call last): File "D:\PyCharm_Community_Edition\helpers\pydev\pydevd.py", line 2060, in <module> main() File "D:\PyCharm_Community_Edition\helpers\pydev\pydevd.py", line 2054, in main globals = debugger.run(setup['file'], None, None, is_module) File "D:\PyCharm_Community_Edition\helpers\pydev\pydevd.py", line 1405, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "D:\PyCharm_Community_Edition\helpers\pydev\pydevd.py", line 1412, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "D:\PyCharm_Community_Edition\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\nnetutils\ONNXConverter\utils\caffe2onnx\convert2onnx.py", line 34, in <module> main(args) File "D:\nnetutils\ONNXConverter\utils\caffe2onnx\convert2onnx.py", line 25, in main graph, params = loadcaffemodel(caffe_graph_path,caffe_params_path) File "D:\nnetutils\ONNXConverter\utils\caffe2onnx\src\load_save_model.py", line 8, in loadcaffemodel text_format.Merge(open(net_path).read(), net) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 690, in Merge allow_unknown_field=allow_unknown_field) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 757, in MergeLines return parser.MergeLines(lines, message) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 782, in MergeLines self._ParseOrMerge(lines, message) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 804, in _ParseOrMerge self._MergeField(tokenizer, message) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 929, in _MergeField merger(tokenizer, message, field) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 1003, in _MergeMessageField self._MergeField(tokenizer, sub_message) File "C:\Users\Fuhrer\AppData\Local\Programs\Python\Python37\lib\site-packages\google\protobuf\text_format.py", line 896, in _MergeField (message_descriptor.full_name, name)) google.protobuf.text_format.ParseError: 4433:3 : Message type "caffe.LayerParameter" has no field named "permute_param".

ZQPei commented 4 years ago

Hi, Zhavoronkov, There might be something wrong with your model itself. The function test_format from protobuf cannot Merge your model to net. Can you send your caffemodel to us so we can debug it for you?

Yrij-Zhavoronkov commented 4 years ago

Do you want this? robo-cars.txt

ZQPei commented 4 years ago

Are there custom layers in your caffe? How about replace these files caffe_upsample.proto and caffe_upsample_pb2.py with the same named files in your caffe?

Yrij-Zhavoronkov commented 4 years ago

Yes, I have long taken proto from caffe SSD, but still can not understand how to write these layers in onnx

link to caffe ssd: https://github.com/weiliu89/caffe/tree/ssd

Yrij-Zhavoronkov commented 4 years ago

proto.zip new proto here)

ZQPei commented 4 years ago

I tried converting on official SSD caffemodel. The things you should do is as follows.

  1. Compile caffe.proto with protoc, then you will get caffe_pb2.py. After that, replace the same files in proto folder. Finally modify from proto import caffe_upsample_pb2 in src/load_save_model.py and op_layer_info.py.
  2. Since there are several custom layers in official SSD, such as Normalize, Flatten, Permute and PriorBox, and now this repository do not support those OPs, you shall add those supports in src/OPs.
Yrij-Zhavoronkov commented 4 years ago

This is already done and I know that they should be added to the src. I don't know how to write Normalize, Flatten, Permute, PriorBox and other layers correctly to onnx. Is there a manual?

ZQPei commented 4 years ago

Here are some exists ops in onnx 1.4.0. Most of the ops in official SSD except PriorBox can be found there. You can add those supports as the same as other ops in src.