Open james77777778 opened 1 year ago
@james77777778 Could you please have a look at the gist in latest TF version and confirm the output? Please feel free to raise the PR to fix the issue ? Thank you!
@sushreebarsa I ran the code you provided and verified that the issue still persists.
(visualization from netron)
I will try to raise the PR when I'm back from my vacation... :)
System information.
Describe the problem.
tf.nn.convolution
produces SpaceToBatchNd-Conv2D-BatchToSpaceNd pattern when we do tflite conversion withkeras.layers.Conv2D
(https://github.com/keras-team/keras/blob/master/keras/layers/convolutional/base_conv.py#L247-L263)Describe the current behavior.
When converting functional model containing
keras.layers.Conv2D
which hasdilation_rate > 1
, the SpaceToBatchNd-Conv2D-BatchToSpaceNd appears and the pattern can be visualized with Netron.Also, we get useless
dilation_h_factor
anddilation_w_factor
because they are always1
.We can fix it by replacing
tf.nn.convolution
withtf.nn.conv2d
using custom layer but it is inconvenient if we want to further optimize the model with tfmot which encourages users to stick to built-in keras layers.Describe the expected behavior.
keras.layers.Conv2D
withdilation_rate > 1
should be converted as expected instead of SpaceToBatchNd-Conv2D-BatchToSpaceNdContributing.
Just one single line modification:
Standalone code to reproduce the issue.