MobileNet-v1[2017-arXiv]

假設input的size爲 3 x 64 x 64, output : 4 x 64 x 64.

常規卷積

                                                  

深度可分離卷積

     

量化對比

  • 參數量

      傳統卷積:d x d x C_in x C_out ;

      深度可分離卷積 :d x d x C_in + C_out x 1 x 1 x C_in ;

      參數比[深度可分離:傳統]:(d x d + C_out) / (d x d x C_out)  ≈ 1 / (d x d)  【if C_out  >>  d x d】 ;

  • 計算量

     傳統卷積:d x d x C_in x C_out x H x W ;

     深度可分離卷積:d x d x C_in x H x W + C_out x 1 x 1 x C_in x H x W ;

     運算量比[深度可分離:傳統] : (d x d + C_out) / (d x d x C_out)  = 1 / C_out + 1 / (d x d)  ≈ 1 / (d x d)  【if C_out  >>  d x d】

Pytorch

  • 常規卷積
nn.Conv2d(inplanes, planes, kernel_size=3, stride, 1, bias=False)
nn.BatchNorm2d(planes)
nn.PReLU(planes)
  • 深度可分離卷積 
nn.Conv2d(inplanes, planes, kernel_size=3, stride, 1, groups=planes, bias=False)
# groups的取值應爲inplanes、planes的公約數,即能夠被inplanes、planes同時整除
# inplanes/groups表示每個group中channel的個數;
# planes/groups表示group中channel被使用幾次;
nn.BatchNorm2d(planes)
nn.PReLU(planes)
nn.Conv2d(planes, planes, 1, 1, 0, bias=False)

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章