AxisCommunications / onnx-to-keras

Convert onnx models exported from pytorch to tensorflow keras models with focus on performace and highleve compatibility.
MIT License
25 stars 13 forks source link

Split grouped convs for tflite compatibility #28

Closed 95hali74 closed 2 years ago

95hali74 commented 3 years ago

See: https://github.com/tensorflow/tensorflow/issues/4004

This PR changes the Conv2D layer creation: group = n_channels -> Depthwise Conv2D group = 1 -> Regular Conv2D else -> Split into group number of Conv2D layers

Is it fine if this is the default behavior or maybe a command line arg (for example "make_tflite_compatible_model") for changing the behavior is prefererad?

xsacha commented 2 years ago

I had a look at this and believed the performance would be affected too much to make it worthwhile and instead opted for removing group convolution from the model. I did the conversion using the 'Openvino2Tensorflow' method, which splits group convolutions in this way.

It might need one of those warnings like when a transpose is injected, to show we are doing a suboptimal change to the model in order to maintain compatibility. See: https://github.com/AxisCommunications/onnx-to-keras/blob/53bce898d3dbc660473bc58f225fb4194b7be095/onnx2keras.py#L42

hakanardo commented 2 years ago

Good idea.

95hali74 commented 2 years ago

I added an OptimizationMissingWarning warning and also made the splitting optional using the arg make_tflite_compatible

95hali74 commented 2 years ago

Currently the tests fails because of a keras version mismatch, se this PR: https://github.com/AxisCommunications/onnx-to-keras/pull/36