【論文読み】 ShuffleNet

#背景
 - これまでの画像認識タスク
    - 深く大きい畳み込みニューラルネット
    - 数十億FLOPSの計算
 - Shuffle Netは
    - 限られた計算量で性能を求めるCNN architecture
    - 数十~数百MFLOPSの計算
    - Channel Shuffle + Group Convolution
    - Xception とResNeXtの1x1Convの非効率さからアイデアを得る

#ShuffleNet
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/27c7942d-bae5-bc1f-df8d-18772bac5d20.png)
Figure2: Shuffle Net Unit
 a) bottleneck unit with depth-wise convolution
 b) ShuffleNet unit with pointwise group convolution
 c) ShuffleNet unit with stride = 2 

##  Group Convolutions
###それぞれのConvolutionの計算量 (B)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/81854718-ffca-3012-c968-e787378e6a1a.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/d2827182-96f8-b785-d7da-851e239d47b0.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/51221077-e23d-3b2b-6118-d44aa58af881.png)

###Xception とResNeXtの1x1Convの非効率さ
1x1Conv, 3x3depth-wise, 1x1Conv の計算量

$B = hwm(c + k^2 + c)$



###ResNet(1x1conv, 3x3conv, 1x1convの計算量)

$B = hw(cm + 9m^2 + cm) = hw(2cm+9m^2)$

 - $B_{1\times1conv} = hwcm$
 - $B_{3\times3 conv} = hwcmk^2$
 - $B_{1\times1conv} = hwcm$

###ResNeXt(1x1conv, 3x3Gconv, 1x1convの計算量)

$B = hw(cm + \frac{9m^2}{g} + cm) = hw(2cm+\frac{9m^2}{g})$

 - $B_{1\times1conv} = hwcm$
 - $B_{3\times3 Gconv} = \frac{hwm^2k^2}{g}$
 - $B_{1\times1conv} = hwcm$

###ShuffleNet(1x1Gconv, 3x3dwconv, 1x1Gconvの計算量)
 
$B = hw(\frac{cm}{g} + 9m + \frac{cm}{g}) = hw(\frac{2cm}{g}+9m)$

 - $B_{1\times1Gconv} = \frac{hwcm}{g}$
 - $B_{3\times3 dwconv} = hwk^2m$
 - $B_{1\times1conv} = hwcm$

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/3ad8d778-9b68-f1cc-3b13-18805a3184e5.png)


## Channel Shuffle

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/3a03d27b-ce16-6230-482f-9a24265d5f29.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/032a37ef-e189-e635-9d12-f9039bf61267.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/b393965f-5ce4-fa24-364a-aff08f3ad076.png)
Table1: ShuffleNet architecture

#モデル評価
## Pointwise Group Convolution
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/74faa0a8-afd8-ab86-74e6-692b216c6eac.png)
Table2: Classification error vs. number of groups g

 - gが増えることでclassification errorが減っていることがわかる
 - 0.5x : g=8の時飽和している
    - gが増えるにつれ、畳み込みフィルタの入力チャネルが少なくなってしまうため？
 - 0.25x : gが大きいほど性能が良い
    - 小さいモデルでは広い特徴マップを取ることで良い結果が出る

## Channel Shuffle vs No Shuffle
 - cross-group information interchange

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/6444ef48-ed3f-751a-eb0b-6560c9febe42.png)
 Table3: ShuffleNet with/withoutchannel shuffle

 - 全体的にShuffleした方が良い結果が出たといえる
 - gが大きい方が良い結果が出ている
    - gを増やすことでシャッフルがよりたくさん行われる

## Comparison with Other Structure Units

 - Stage 2-4のShuffleNet unitsをそれぞれ他のstructureに置き換える
 - channel数を調節してcomplexityを調節

   ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/f57374a4-2ec0-cbe6-81e2-84fbedea1426.png)
table 4: classficiation error vs various structure


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/9038f449-4df5-ffe1-e4ab-7994853bd975.png)
table 6: Complexity comparison

- 圧倒的に小さいcomplexityで同じような性能を出すことができる


## Comparison with MobileNets and Other Frameworks
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/27157e0d-34de-72b0-5b9a-fc5f50cc4e7c.png)
table 5: ShuffleNet vs. MobileNet on ImageNet Classification

 - Shuffle Net > MobileNet for all complexities
 - Shuffle Netは深さではなく効率の良い構造で良い精度を出している
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/ee7d6ed8-08fb-5a5c-60b6-8475b1107a74.png)
table 7: Object detection results on MS COCO

#推論時間
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/455946/bb697f1c-199d-6bbe-a73b-f40f3109d4d1.png)
table 8: actual inference time on a mobile device