SoftwareGift / FeatherNets_Face-Anti-spoofing-Attack-Detection-Challenge-CVPR2019

Code for 3rd Place Solution in Face Anti-spoofing Attack Detection Challenge @ CVPR2019,model only 0.35M!!! 1.88ms(CPU)
Other
928 stars 282 forks source link

How to replace "nn.AvgPool2d" to "nn.AdaptiveAvgPool2d" ? #51

Open SeaRecluse opened 5 years ago

SeaRecluse commented 5 years ago

I use the MobileNetV2 and I want to use your model on mobile devices by NCNN.
I convert the model to onnx.When I want to convert the MobileNetV2.onnx by NCNN.The layer ReduceMea n not supported.But NCNN's contributor tell me if I can replace "nn.AvgPool2d" to "nn.AdaptiveAvgPool2d" before the last conv.I will get a usful model. https://github.com/Tencent/ncnn/issues/1092

But I can't find the "nn.AvgPool2d"?Where I can replace it?Thx.

nihui commented 5 years ago

https://github.com/SoftwareGift/FeatherNets_Face-Anti-spoofing-Attack-Detection-Challenge-CVPR2019/blob/77d27c0f3237419030bc0073c951792b5588704d/models/mobilenetv2.py#L109

SeaRecluse commented 5 years ago

https://github.com/SoftwareGift/FeatherNets_Face-Anti-spoofing-Attack-Detection-Challenge-CVPR2019/blob/77d27c0f3237419030bc0073c951792b5588704d/models/mobilenetv2.py#L109

Great Nihui.Thank you so much😂 I still don't know how to change it.I just learned the pytorch API doc.

SeaRecluse commented 5 years ago

I change the code like this. But It doesn't work.

self.avg_pool = nn.AdaptiveAvgPool2d(1)

def forward(self, x):
    x = self.features(x)
    b, c, _, _ = x.size()
    y = self.avg_pool(x).view(b, c)
    x = self.classifier(y)
    return x