dnn : Fix convolution asymmetric padding bug in onnx importer#20394
dnn : Fix convolution asymmetric padding bug in onnx importer#20394opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
| TEST_P(Test_ONNX_layers, Convolution) | ||
| { | ||
| testONNXModels("convolution"); | ||
| testONNXModels("conv_asymmetric_pads"); |
There was a problem hiding this comment.
Is it possible to provide ONNX test data generator code (generate_onnx_models.py in opencv_extra PR) ?
There was a problem hiding this comment.
No, I don't think its possible. torch.onnx.export() does not fuses padding with conv layer which is required to test this change.
As mentioned in description, tools like tf2onnx and keras2onnx use this type of fusion (onnx/tensorflow-onnx#334). The onnx model in opencv_extra has been generated using tf2onnx.
There was a problem hiding this comment.
The onnx model in opencv_extra has been generated using tf2onnx.
tf2onnx has python interface, would it be possible to use that?
There was a problem hiding this comment.
tf2onnx has python interface
Yes it can be used, but the original network is built using tensorflow. generate_onnx_models.py uses Pytorch.
Code used to generate onnx model
import tensorflow as tf
import tf2onnx
tf.keras.backend.set_image_data_format('channels_first')
inp = tf.keras.layers.Input(batch_shape = (1, 2, 3, 4))
pad = tf.keras.layers.ZeroPadding2D(padding = ((2, 1), (2, 1)))(inp)
out = tf.keras.layers.Conv2D(3, kernel_size = 3)(pad)
model = tf.keras.Model(inp, out)
onnx_model, _ = tf2onnx.convert.from_keras(model, output_path="/conv_asymmetric_pads.onnx")There was a problem hiding this comment.
Perhaps it makes sense to create new file like generate_onnx_tf.py (or tf2 to mention TensorFlow 2.x).
BTW, Old file can be renamed to generate_onnx_pytorch.py separately.
Update: removed _testdata from names.
There was a problem hiding this comment.
Sounds good. Should I add these 2 changes in opencv_extra PR?
There was a problem hiding this comment.
Feel free to create a new file in opencv_extra.
It would be nice if you can prepare requirements-tf.txt file too (list required pip packages there, pip freeze may help with that, example)
alalek
left a comment
There was a problem hiding this comment.
Looks good to me 👍
Thank you for contribution!
bf84953 to
96d35f7
Compare
|
Squashed commits into one |
Merge with extra : opencv/opencv_extra#881
relates #19316 #19499 #19696 #19957
Using tools like tf2onnx and keras2onnx, to convert tensorflow networks to onnx format, fuses zero-padding layer with convolution layer but does not check if the padding is symmetric when importing such converted networks.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.