Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroPadding2D slow down the inference #2

Open
vinh-cao opened this issue Dec 21, 2021 · 1 comment
Open

ZeroPadding2D slow down the inference #2

vinh-cao opened this issue Dec 21, 2021 · 1 comment

Comments

@vinh-cao
Copy link

Hi Thang,

like the title already mentioned, using the ZeroPadding2D layer extremely slow down the inference, so we don't gain much from removing 1x1-conv and skips branches.

I found out that we only need ZeroPadding2D for 3x3 conv with stride 2 branches (halving the dimension). Meaning: you can remove most of the ZeroPadding2D layers and set padding to 'same' for those cases.

Best,
Vinh

@vinh-cao
Copy link
Author

vinh-cao commented Jan 4, 2022

found out, that Conv2D with padding = same and stride = 2, tensorflow puts 2 new lines on the bottom and right side of the input feature map. Therfore, the perception field of 1x1 and 3x3 convolution is not the same.
You can fix the bug when converting the deploy model by padding the 1x1 to 3x3 with:
padding = tf.constant([[0, 2], [0, 2], [0, 0], [0, 0]])

This way, you can drop all ZeroPadding2D layers and just use 'same'-padding of Conv2D layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant