Network Compression
===
###### tags: `DL`
{%hackmd theme-dark %}

## Network Pruning

讓一個已經學完的model中的neuron進行刪減,讓整個網路變得更瘦。
* weight和neuron pruning差別在於prune掉一個neuron就等於是把一個matrix的整個column全部砍掉。但如此一來速度就會比較快。因為neuron pruning後matrix整體變小,但weight pruning大小不變,只是有很多空洞。
* 在gpu加速上較為困難,因為每次訓練時都要檢查哪些是不需要的neuron,不容易平行。
* MorphNet
## Parameter Quantization
利用較少的bits來簡化原本的weight,進而減少計算量。
1. Using less bits to represent a value
2. Weight clustering

3. Represent frequent clusters by less bits, represent rare clusters by more bits. ex: Huffman encoding

* XNOR-Net
## Efficient Convolutional Filters and Matrix Factorization
改變CNN內layers組成,利用filter加上矩陣分解,像是MxN的矩陣拆成MxK、KxN,藉由減少參數進而減少計算量。
* MobileNet
1. DW(Depthwise Convolution Layer)像成一張feature map經過一個filter(KxK)處理後
2. PW(Pointwise Convolution Layer)把所有feature map的單個pixel資訊(1x1)合在一起(就是1個pixel的Fully Connected Layer)

* ShuffleNet
1. GC(Group Convolution Layer)就是把feature map分組,讓他們自己過Convolution Layer後再重新Concat起來。算是一般的Convolution和Depthwise Convolution的折衷版。
2. Group Convolution的Group=Input Feautures數就會是Depthwise Convolution(因為每個Channel都各自獨立),Group=1就會是一般的Convolution(因為就等於沒有Group)。

3. 由於分群的關係,feature只會在自己群傳遞,對模型的訓練不好,因此會需要shffle的方式來打亂讓各個group可以互相交流。

## Neural Architecture Search
訓練一個很大的模型,找出合適各個裝置的子模型
* DARTS: Differentiable Architecture Search
* Once-for-all

## Knowledge Distillation

讓已經做得很好的大model們去告訴小model"如何"學習。 而我們如何做到這件事情呢? 就是利用大model預測的logits給小model當作標準就可以了。
* Why work?
1. 例如當data不是很乾淨的時候,對一般的model來說他是個noise,只會干擾學習。透過去學習其他大model預測的logits會比較好。
2. label和label之間可能有關連,這可以引導小model去學習。例如數字8可能就和6,9,0有關係。
3. 弱化已經學習不錯的target(?),避免讓其gradient干擾其他還沒學好的task。