tonylins / pytorch-mobilenet-v2

A PyTorch implementation of MobileNet V2 architecture and pretrained model.
Apache License 2.0
1.37k stars 328 forks source link

depthwise "separable" convolution not implemented correctly? #24

Closed semin-park closed 5 years ago

semin-park commented 5 years ago

First of all, great work :)

I'm just a little bit concerned about your implementation of the depthwise separable convolution. AFAIK, it's supposed to be a depthwise convolution followed by a pointwise convolution.

What I am thinking of is something like this:

cin, cout = channels_in, channels_out

depthwise = nn.Conv2d(cin, cin, kernel_size=3, padding=(1,1), groups=cin)
pointwise = nn.Conv2d(cin, cout, kernel_size=1)

depthwise_separable_convolution = nn.Sequential(
    depthwise,
    pointwise
)

But in your implementation, you implemented it as a single convolution, which I believe is a depthwise convolution, but not a depthwise "separable" convolution.

tonylins commented 5 years ago

Please see the InvertedResidual class.