gmalivenko / pytorch2keras

PyTorch to Keras model convertor
https://pytorch2keras.readthedocs.io/en/latest/
MIT License
858 stars 143 forks source link

Use DepthwiseConv2D rather than SeparableConv2D with no-op pointwise conv #68

Closed ElteHupkes closed 5 years ago

ElteHupkes commented 5 years ago

I noticed that my converted frozen .pb was much larger than a very similar model natively defined in Tensorflow. This turned out to be because of the pointwise convolution weights stored in the converted model - but these weights were all zero. I figured that instead of using a separable conv with a no-op pointwise conv, we can simply use a depthwise conv. I replaced it, and everything appears to be working as expected. tests/layers/convolutions/conv2d.py runs with a max error of 8.344650268554688e-07.

There is one caveat, which is that for whatever reason the dilation_rate parameter of keras.layers.DepthwiseConv2D isn't explicitly documented. This seems to be a documentation error rather than it being an unsupported feature, because it is most definitely used in the functional layer.

EDIT: Oh, and as a result, my .pb file went from 4.4mb to 1.3mb with the exact same output error (compared to the PyTorch model).