YonghaoHe / LFFD-A-Light-and-Fast-Face-Detector-for-Edge-Devices

A light and fast one class detection framework for edge devices. We provide face detector, head detector, pedestrian detector, vehicle detector......
MIT License
1.31k stars 329 forks source link

Trying to convert to ONNX - converter fails with sliceerror #73

Closed krishnak closed 4 years ago

krishnak commented 4 years ago

I am trying to convert the head detection model from MXNET to ONNX using the steps mentioned in https://github.com/onnx/tutorials/blob/master/tutorials/MXNetONNXExport.ipynb

My setup is as follows

Requirement already satisfied: onnx in ./kenv/lib/python3.6/site-packages (1.6.0) Requirement already satisfied: six in /home/username/.local/lib/python3.6/site-packages (from onnx) (1.13.0) Requirement already satisfied: protobuf in ./kenv/lib/python3.6/site-packages (from onnx) (3.11.1) Requirement already satisfied: typing-extensions>=3.6.2.1 in ./kenv/lib/python3.6/site-packages (from onnx) (3.7.4.1) Requirement already satisfied: numpy in /home/username/.local/lib/python3.6/site-packages (from onnx) (1.17.4) Requirement already satisfied: setuptools in ./kenv/lib/python3.6/site-packages (from protobuf->onnx) (42.0.2)

When trying to use the code, I get the following error, any workarounds?

$ python mxconverter.py 
INFO:root:Converting json and weight file to sym and params
[20:53:26] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.5.0. Attempting to upgrade...
[20:53:26] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded!
Traceback (most recent call last):
  File "mxconverter.py", line 17, in <module>
    converted_model_path = onnx_mxnet.export_model(sym, params, [input_shape], np.float32, onnx_file)
  File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/export_model.py", line 83, in export_model
    verbose=verbose)
  File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/export_onnx.py", line 312, in create_onnx_graph_proto
    checker.check_graph(graph)
  File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/onnx/checker.py", line 53, in checker
    proto.SerializeToString(), ctx)
onnx.onnx_cpp2py_export.checker.ValidationError: Node (slice_axis16) has input size 1 not in range [min=3, max=5].

==> Context: Bad node spec: input: "softmax0" output: "slice_axis16" name: "slice_axis16" op_type: "Slice" attribute { name: "axes" ints: 1 type: INTS } attribute { name: "ends" ints: 1 type: INTS } attribute { name: "starts" ints: 0 type: INTS }
krishnak commented 4 years ago

The error in verbose mode is as below [22:19:54] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded! INFO:root:Converting idx: 0, op: null, name: data INFO:root:Converting idx: 1, op: _minus_scalar, name: _minusscalar1 INFO:root:Converting idx: 2, op: _div_scalar, name: _divscalar1 INFO:root:Converting idx: 3, op: null, name: conv1_weight INFO:root:Converting idx: 4, op: null, name: conv1_bias INFO:root:Converting idx: 5, op: Convolution, name: conv1 INFO:root:Converting idx: 6, op: Activation, name: relu_conv1 INFO:root:Converting idx: 7, op: null, name: conv2_weight INFO:root:Converting idx: 8, op: null, name: conv2_bias INFO:root:Converting idx: 9, op: Convolution, name: conv2 INFO:root:Converting idx: 10, op: Activation, name: relu_conv2 INFO:root:Converting idx: 11, op: null, name: conv3_weight INFO:root:Converting idx: 12, op: null, name: conv3_bias INFO:root:Converting idx: 13, op: Convolution, name: conv3 INFO:root:Converting idx: 14, op: Activation, name: relu_conv3 INFO:root:Converting idx: 15, op: null, name: conv4_weight INFO:root:Converting idx: 16, op: null, name: conv4_bias INFO:root:Converting idx: 17, op: Convolution, name: conv4 INFO:root:Converting idx: 18, op: elemwise_add, name: _plus6 INFO:root:Converting idx: 19, op: Activation, name: relu_conv4 INFO:root:Converting idx: 20, op: null, name: conv5_weight INFO:root:Converting idx: 21, op: null, name: conv5_bias INFO:root:Converting idx: 22, op: Convolution, name: conv5 INFO:root:Converting idx: 23, op: Activation, name: relu_conv5 INFO:root:Converting idx: 24, op: null, name: conv6_weight INFO:root:Converting idx: 25, op: null, name: conv6_bias INFO:root:Converting idx: 26, op: Convolution, name: conv6 INFO:root:Converting idx: 27, op: elemwise_add, name: _plus7 INFO:root:Converting idx: 28, op: Activation, name: relu_conv6 INFO:root:Converting idx: 29, op: null, name: conv7_weight INFO:root:Converting idx: 30, op: null, name: conv7_bias INFO:root:Converting idx: 31, op: Convolution, name: conv7 INFO:root:Converting idx: 32, op: Activation, name: relu_conv7 INFO:root:Converting idx: 33, op: null, name: conv8_weight INFO:root:Converting idx: 34, op: null, name: conv8_bias INFO:root:Converting idx: 35, op: Convolution, name: conv8 INFO:root:Converting idx: 36, op: elemwise_add, name: _plus8 INFO:root:Converting idx: 37, op: Activation, name: relu_conv8 INFO:root:Converting idx: 38, op: null, name: conv8_1_weight INFO:root:Converting idx: 39, op: null, name: conv8_1_bias INFO:root:Converting idx: 40, op: Convolution, name: conv8_1 INFO:root:Converting idx: 41, op: Activation, name: relu_conv8_1 INFO:root:Converting idx: 42, op: null, name: conv8_2_score_weight INFO:root:Converting idx: 43, op: null, name: conv8_2_score_bias INFO:root:Converting idx: 44, op: Convolution, name: conv8_2_score INFO:root:Converting idx: 45, op: Activation, name: relu_conv8_2_score INFO:root:Converting idx: 46, op: null, name: conv8_3_score_weight INFO:root:Converting idx: 47, op: null, name: conv8_3_score_bias INFO:root:Converting idx: 48, op: Convolution, name: conv8_3_score INFO:root:Converting idx: 49, op: softmax, name: softmax0 INFO:root:Converting idx: 50, op: slice_axis, name: slice_axis16 INFO:root:Output node is: slice_axis16 INFO:root:Converting idx: 51, op: null, name: conv8_2_bbox_weight INFO:root:Converting idx: 52, op: null, name: conv8_2_bbox_bias INFO:root:Converting idx: 53, op: Convolution, name: conv8_2_bbox INFO:root:Converting idx: 54, op: Activation, name: relu_conv8_2_bbox INFO:root:Converting idx: 55, op: null, name: conv8_3_bbox_weight INFO:root:Converting idx: 56, op: null, name: conv8_3_bbox_bias INFO:root:Converting idx: 57, op: Convolution, name: conv8_3_bbox INFO:root:Output node is: conv8_3_bbox INFO:root:Converting idx: 58, op: null, name: conv9_weight INFO:root:Converting idx: 59, op: null, name: conv9_bias INFO:root:Converting idx: 60, op: Convolution, name: conv9 INFO:root:Converting idx: 61, op: Activation, name: relu_conv9 INFO:root:Converting idx: 62, op: null, name: conv10_weight INFO:root:Converting idx: 63, op: null, name: conv10_bias INFO:root:Converting idx: 64, op: Convolution, name: conv10 INFO:root:Converting idx: 65, op: Activation, name: relu_conv10 INFO:root:Converting idx: 66, op: null, name: conv11_weight INFO:root:Converting idx: 67, op: null, name: conv11_bias INFO:root:Converting idx: 68, op: Convolution, name: conv11 INFO:root:Converting idx: 69, op: elemwise_add, name: _plus9 INFO:root:Converting idx: 70, op: Activation, name: relu_conv11 INFO:root:Converting idx: 71, op: null, name: conv11_1_weight INFO:root:Converting idx: 72, op: null, name: conv11_1_bias INFO:root:Converting idx: 73, op: Convolution, name: conv11_1 INFO:root:Converting idx: 74, op: Activation, name: relu_conv11_1 INFO:root:Converting idx: 75, op: null, name: conv11_2_score_weight INFO:root:Converting idx: 76, op: null, name: conv11_2_score_bias INFO:root:Converting idx: 77, op: Convolution, name: conv11_2_score INFO:root:Converting idx: 78, op: Activation, name: relu_conv11_2_score INFO:root:Converting idx: 79, op: null, name: conv11_3_score_weight INFO:root:Converting idx: 80, op: null, name: conv11_3_score_bias INFO:root:Converting idx: 81, op: Convolution, name: conv11_3_score INFO:root:Converting idx: 82, op: softmax, name: softmax1 INFO:root:Converting idx: 83, op: slice_axis, name: slice_axis17 INFO:root:Output node is: slice_axis17 INFO:root:Converting idx: 84, op: null, name: conv11_2_bbox_weight INFO:root:Converting idx: 85, op: null, name: conv11_2_bbox_bias INFO:root:Converting idx: 86, op: Convolution, name: conv11_2_bbox INFO:root:Converting idx: 87, op: Activation, name: relu_conv11_2_bbox INFO:root:Converting idx: 88, op: null, name: conv11_3_bbox_weight INFO:root:Converting idx: 89, op: null, name: conv11_3_bbox_bias INFO:root:Converting idx: 90, op: Convolution, name: conv11_3_bbox INFO:root:Output node is: conv11_3_bbox INFO:root:Converting idx: 91, op: null, name: conv12_weight INFO:root:Converting idx: 92, op: null, name: conv12_bias INFO:root:Converting idx: 93, op: Convolution, name: conv12 INFO:root:Converting idx: 94, op: Activation, name: relu_conv12 INFO:root:Converting idx: 95, op: null, name: conv13_weight INFO:root:Converting idx: 96, op: null, name: conv13_bias INFO:root:Converting idx: 97, op: Convolution, name: conv13 INFO:root:Converting idx: 98, op: Activation, name: relu_conv13 INFO:root:Converting idx: 99, op: null, name: conv14_weight INFO:root:Converting idx: 100, op: null, name: conv14_bias INFO:root:Converting idx: 101, op: Convolution, name: conv14 INFO:root:Converting idx: 102, op: elemwise_add, name: _plus10 INFO:root:Converting idx: 103, op: Activation, name: relu_conv14 INFO:root:Converting idx: 104, op: null, name: conv14_1_weight INFO:root:Converting idx: 105, op: null, name: conv14_1_bias INFO:root:Converting idx: 106, op: Convolution, name: conv14_1 INFO:root:Converting idx: 107, op: Activation, name: relu_conv14_1 INFO:root:Converting idx: 108, op: null, name: conv14_2_score_weight INFO:root:Converting idx: 109, op: null, name: conv14_2_score_bias INFO:root:Converting idx: 110, op: Convolution, name: conv14_2_score INFO:root:Converting idx: 111, op: Activation, name: relu_conv14_2_score INFO:root:Converting idx: 112, op: null, name: conv14_3_score_weight INFO:root:Converting idx: 113, op: null, name: conv14_3_score_bias INFO:root:Converting idx: 114, op: Convolution, name: conv14_3_score INFO:root:Converting idx: 115, op: softmax, name: softmax2 INFO:root:Converting idx: 116, op: slice_axis, name: slice_axis18 INFO:root:Output node is: slice_axis18 INFO:root:Converting idx: 117, op: null, name: conv14_2_bbox_weight INFO:root:Converting idx: 118, op: null, name: conv14_2_bbox_bias INFO:root:Converting idx: 119, op: Convolution, name: conv14_2_bbox INFO:root:Converting idx: 120, op: Activation, name: relu_conv14_2_bbox INFO:root:Converting idx: 121, op: null, name: conv14_3_bbox_weight INFO:root:Converting idx: 122, op: null, name: conv14_3_bbox_bias INFO:root:Converting idx: 123, op: Convolution, name: conv14_3_bbox INFO:root:Output node is: conv14_3_bbox INFO:root:Converting idx: 124, op: null, name: conv15_weight INFO:root:Converting idx: 125, op: null, name: conv15_bias INFO:root:Converting idx: 126, op: Convolution, name: conv15 INFO:root:Converting idx: 127, op: Activation, name: relu_conv15 INFO:root:Converting idx: 128, op: null, name: conv16_weight INFO:root:Converting idx: 129, op: null, name: conv16_bias INFO:root:Converting idx: 130, op: Convolution, name: conv16 INFO:root:Converting idx: 131, op: Activation, name: relu_conv16 INFO:root:Converting idx: 132, op: null, name: conv17_weight INFO:root:Converting idx: 133, op: null, name: conv17_bias INFO:root:Converting idx: 134, op: Convolution, name: conv17 INFO:root:Converting idx: 135, op: elemwise_add, name: _plus11 INFO:root:Converting idx: 136, op: Activation, name: relu_conv17 INFO:root:Converting idx: 137, op: null, name: conv17_1_weight INFO:root:Converting idx: 138, op: null, name: conv17_1_bias INFO:root:Converting idx: 139, op: Convolution, name: conv17_1 INFO:root:Converting idx: 140, op: Activation, name: relu_conv17_1 INFO:root:Converting idx: 141, op: null, name: conv17_2_score_weight INFO:root:Converting idx: 142, op: null, name: conv17_2_score_bias INFO:root:Converting idx: 143, op: Convolution, name: conv17_2_score INFO:root:Converting idx: 144, op: Activation, name: relu_conv17_2_score INFO:root:Converting idx: 145, op: null, name: conv17_3_score_weight INFO:root:Converting idx: 146, op: null, name: conv17_3_score_bias INFO:root:Converting idx: 147, op: Convolution, name: conv17_3_score INFO:root:Converting idx: 148, op: softmax, name: softmax3 INFO:root:Converting idx: 149, op: slice_axis, name: slice_axis19 INFO:root:Output node is: slice_axis19 INFO:root:Converting idx: 150, op: null, name: conv17_2_bbox_weight INFO:root:Converting idx: 151, op: null, name: conv17_2_bbox_bias INFO:root:Converting idx: 152, op: Convolution, name: conv17_2_bbox INFO:root:Converting idx: 153, op: Activation, name: relu_conv17_2_bbox INFO:root:Converting idx: 154, op: null, name: conv17_3_bbox_weight INFO:root:Converting idx: 155, op: null, name: conv17_3_bbox_bias INFO:root:Converting idx: 156, op: Convolution, name: conv17_3_bbox INFO:root:Output node is: conv17_3_bbox Traceback (most recent call last): File "/home/username/visualstudioworkspace/python/mxconverter.py", line 24, in converted_model_path = onnx_mxnet.export_model(net_symbol, net_params, [input_shape], np.float32, onnx_file,verbose=True) File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/export_model.py", line 87, in export_model verbose=verbose) File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/mxnet/contrib/onnx/mx2onnx/export_onnx.py", line 312, in create_onnx_graph_proto checker.check_graph(graph) File "/home/username/tensorflowpython/kenv/lib/python3.6/site-packages/onnx/checker.py", line 53, in checker proto.SerializeToString(), ctx) onnx.onnx_cpp2py_export.checker.ValidationError: Node (slice_axis16) has input size 1 not in range [min=3, max=5].

il-easteregg commented 4 years ago

Make sure you are using onnx==1.2.1, as advised by MXNet. This solved the error for me.