RepVGG-Tensorflow-2 icon indicating copy to clipboard operation
RepVGG-Tensorflow-2 copied to clipboard

ZeroPadding2D slow down the inference

Open vinh-cao opened this issue 2 years ago • 1 comments

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 avatar Dec 21 '21 12:12 vinh-cao

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.

vinh-cao avatar Jan 04 '22 22:01 vinh-cao