Pruning Techniques for Deep Neural Networks
1.剪枝
1.1 剪枝分类
此内容来自https://www.cs.princeton.edu/courses/archive/spring21/cos598D/lectures/pruning.pdf。
1.1.1 structured pruning和unstructured pruning
1.1.2 Local pruning和global pruning
1.2 根据BN层scale系数进行的剪枝
此部分主要参考的论文是Learning Efficient Convolutional Networks through Network Slimming。
CONV-BN-Relu可以说是当前深度学习模型中比较常见的元素。BN层的scale系数是和conv输出特征图的channel是一一对应的。此论文使用scale系数绝对值的大小,对特征图进行剪枝。
剪枝原理、流程如下图:
1.3 使用Network Slimming对yolov3进行剪枝
yolov3是常用的object detection模型之一。
使用Network Slimming对yolov3进行剪枝(剪枝比例可调)后,params及flops都有明显的下降:
2.知识蒸馏
Hinton论文Distilling the Knowledge in a Neural Network可以说是知识蒸馏奠基性的文章。
知识蒸馏由teacher net以及student net组成,teacher net规模较大,student net规模小。
其要旨是teacher net输出结果中的重要信息,如对于一个分类模型,不仅仅是one-hot编码的分类结果,其softmax结果给出的信息(有些文章中称为dark information)同样很重要。
对于softmax函数,T值越大,对应于结果值越softer;
有些文章中给出的损失函数分别结合了student net输出结果与gt label(即hard label)、Teacher net的soft label的交叉熵。
可以为两部分赋予不同的系数 α \alpha α、 β \beta β,来表征模型对gt以及Teach net输出的结果的信任/重视程度。
下图是http://cs230.stanford.edu/files_winter_2018/projects/6940224.pdf中的结论:
使用了知识蒸馏(KD),结果都有一定的提升;
student net复杂点,结果相对更好。
另外,http://cs230.stanford.edu/files_winter_2018/projects/6940224.pdf中还做了如下试验:
图(a)说明,随着T越高,softmax结果越来越softer;T=20时,肉眼已经看不清楚分类结果;
图(b)说明,4个随机图片样本,未经过知识蒸馏学习的student net输出结果是错的,而经过知识蒸馏,学习到Teacher net输出的dark information后,student net给出了正确的分类结果。
参考文献
[1] https://pytorch.org/tutorials/intermediate/pruning_tutorial.html
[2] https://opendatascience.com/what-is-pruning-in-machine-learning/
[3] https://jacobgil.github.io/deeplearning/pruning-deep-learning
[4] Learning Efficient Convolutional Networks through Network Slimming
[5] Distilling the Knowledge in a Neural Network
[6] https://github.com/peterliht/knowledge-distillation-pytorch
[7] http://cs230.stanford.edu/files_winter_2018/projects/6940224.pdf
[8] https://intellabs.github.io/distiller/knowledge_distillation.html
[9] https://het-shah.github.io/blog/2020/Knowledge-Distillation/
[10] https://devopedia.org/knowledge-distillation
[11] https://github.com/zbyuan/pruning_yolov3/blob/master/prune.py
[12] How to compress a neural network
[13] https://www.cs.princeton.edu/courses/archive/spring21/cos598D/lectures/pruning.pdf