Baidu Paddle Slim的方案
宏观介绍:https://mp.weixin.qq.com/s/EhMnYcOZkuNFVbnYOC2rSw
https://github.com/PaddlePaddle/PaddleSlim
https://github.com/PaddlePaddle/PaddleDetection
蒸馏
- output distillation: soft target
- feature distillation: FSP矩阵L2loss
- 由于小模型和大模型之间通过L2 loss进行监督,必须保证两个FSP矩阵的维度必须相同,而FSP矩阵的维度为M*N,其中M、N分别为输入和输出特征的channel数,因此大模型和小模型的FSP矩阵需要一一对应。
- 文章A Gift from Knowledge Distillation: Fast Optimization, Network Minimization and Transfer Learning
- 代码https://github.com/PaddlePaddle/PaddleSlim/blob/912a81fb021b9c453bb28fc1bd5dfeb74244a716/paddleslim/dist/single_distiller.py#L98
paddleslim上pascal voc的蒸馏方案
- https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/distillation/README.md#mobilenetv1-yolov3%E5%9C%A8voc%E6%95%B0%E6%8D%AE%E9%9B%86%E4%B8%8A%E7%9A%84%E8%92%B8%E9%A6%8F
- ResNet34-YOLOv3 蒸馏MobileNetV1-YOLOv3
- 在三个计算yololoss的特征图层做l2 loss
paddleslim上coco的蒸馏方案
- Object detection at 200 Frames Per Second
- https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/slim/distillation/README.md#mobilenetv1-yolov3%E5%9C%A8coco%E6%95%B0%E6%8D%AE%E9%9B%86%E4%B8%8A%E7%9A%84%E8%92%B8%E9%A6%8F
- https://github.com/PaddlePaddle/PaddleDetection/blob/release%2F0.2/slim/distillation/distill.py#L53
- ResNet34-YOLOv3 蒸馏MobileNetV1-YOLOv3
- output distillation,但是coco很难,teacher预测的box中有大量的负样本,会有严重的类别不均衡问题,解决方案:
- objectness正常蒸馏 一个gt和一个teacher 的输出共同约束
- 但是在box和cls的蒸馏loss前加一个objectness的系数,即objectness较高的bbox才会对student network的最终损失函数产生贡献,低的话就不产生共享,这就是objectness scaled distillation
搜索
- 模拟退火(Simulated Annealing, 简称SA)算法,相比传统RL算法,收敛速度更快,迭代步骤更少。支持分布式SA搜索策略,确保40GPU卡以内搜索速度线性加速。https://paddlepaddle.github.io/PaddleSlim/tutorials/nas_demo/
- one-shot nashttps://paddlepaddle.github.io/PaddleSlim/tutorials/one_shot_nas_demo/
- 定义超网络
- 训练超网络
- 基于超网络搜索子网络
- 训练最佳子网络
- 模型延迟评估:由于硬件平台限制,每次评估时间很慢,可以给出一个预估方案
- 配置硬件延时评估器
- 获取搜索空间中所有不重复的 op 及其参数
- 获取每组 op 及其参数的延时
- 评估模型延时
- 获取给定模型的所有 op 及其参数
- 根据给定模型的所有 op 及参数,利用延时评估器去估计模型的延时
- 配置硬件延时评估器
卷积核剪裁
基于敏感度剪裁卷积网络https://paddlepaddle.github.io/PaddleSlim/algo/algo.html#id15
- layer的剪裁比例与其敏感度成反比
- 优先剪裁layer内l1_norm相对低的filter
量化
https://paddlepaddle.github.io/PaddleSlim/algo/algo.html#quantization-aware-training
- 训练时量化
- 训练后量化
还没人转发这篇日记