Skip to content

Latest commit

 

History

History
 
 

slim

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

模型压缩

在PaddleDetection中, 提供了基于PaddleSlim进行模型压缩的完整教程和benchmark。目前支持的方法:

推荐您使用剪裁和蒸馏联合训练,或者使用剪裁和量化,进行检测模型压缩。 下面以YOLOv3为例,进行剪裁、蒸馏和量化实验。

实验环境

  • Python 3.7+
  • PaddlePaddle >= 2.0.1
  • PaddleSlim >= 2.0.0
  • CUDA 9.0+
  • cuDNN >=7.5

注意: 量化训练需要依赖Paddle develop分支,可在PaddlePaddle每日版本中下载安装合适的PaddlePaddle版本。

安装PaddleSlim

  • 方法一:直接安装:
pip install paddleslim -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 方法二:编译安装:
git clone https://github.com/PaddlePaddle/PaddleSlim.git
cd PaddleSlim
python setup.py install

快速开始

训练

python tools/train.py -c configs/{MODEL.yml} --slim_config configs/slim/{SLIM_CONFIG.yml}
  • -c: 指定模型配置文件。
  • --slim_config: 指定压缩策略配置文件。

评估

python tools/eval.py -c configs/{MODEL.yml} --slim_config configs/slim/{SLIM_CONFIG.yml} -o weights=output/{SLIM_CONFIG}/model_final
  • -c: 指定模型配置文件。
  • --slim_config: 指定压缩策略配置文件。
  • -o weights: 指定压缩算法训好的模型路径。

测试

python tools/infer.py -c configs/{MODEL.yml} --slim_config configs/slim/{SLIM_CONFIG.yml} \
    -o weights=output/{SLIM_CONFIG}/model_final
    --infer_img={IMAGE_PATH}
  • -c: 指定模型配置文件。
  • --slim_config: 指定压缩策略配置文件。
  • -o weights: 指定压缩算法训好的模型路径。
  • --infer_img: 指定测试图像路径。

动转静导出模型

python tools/export_model.py -c configs/{MODEL.yml} --slim_config configs/slim/{SLIM_CONFIG.yml} -o weights=output/{SLIM_CONFIG}/model_final
  • -c: 指定模型配置文件。
  • --slim_config: 指定压缩策略配置文件。
  • -o weights: 指定压缩算法训好的模型路径。

Benchmark

剪裁

Pascal VOC上benchmark

模型 压缩策略 GFLOPs 模型体积(MB) 输入尺寸 预测时延(SD855) Box AP 下载 模型配置文件 压缩算法配置文件
YOLOv3-MobileNetV1 baseline 24.13 93 608 289.9ms 75.1 下载链接 配置文件 -
YOLOv3-MobileNetV1 剪裁-l1_norm(sensity) 15.78(-34.49%) 66(-29%) 608 - 78.4(+3.3) 下载链接 配置文件 slim配置文件
  • 目前剪裁支持YOLO系列、SSD、TTFNet、BlazeFace,其余模型正在开发支持中。
  • SD855预测时延为使用PaddleLite部署,使用arm8架构并使用4线程(4 Threads)推理时延。

量化

COCO上benchmark

模型 压缩策略 输入尺寸 Box AP 下载 模型配置文件 压缩算法配置文件
YOLOv3-MobileNetV1 baseline 608 28.8 下载链接 配置文件 -
YOLOv3-MobileNetV1 普通在线量化 608 30.5 (+1.7) 下载链接 配置文件 slim配置文件
YOLOv3-MobileNetV3 baseline 608 31.4 下载链接 配置文件 -
YOLOv3-MobileNetV3 PACT在线量化 608 29.1 (-2.3) 下载链接 配置文件 slim配置文件
YOLOv3-DarkNet53 baseline 608 39.0 下载链接 配置文件 -
YOLOv3-DarkNet53 普通在线量化 608 38.8 (-0.2) 下载链接 配置文件 slim配置文件
SSD-MobileNet_v1 baseline 300 73.8 下载链接 配置文件 -
SSD-MobileNet_v1 普通在线量化 300 72.9(-0.9) 下载链接 配置文件 slim配置文件
Mask-ResNet50-FPN baseline (800, 1333) 39.2/35.6 下载链接 配置文件 -
Mask-ResNet50-FPN 普通在线量化 (800, 1333) 39.7(+0.5)/35.9(+0.3) 下载链接 配置文件 slim配置文件

蒸馏

COCO上benchmark

模型 压缩策略 输入尺寸 Box AP 下载 模型配置文件 压缩算法配置文件
YOLOv3-MobileNetV1 baseline 608 29.4 下载链接 配置文件 -
YOLOv3-MobileNetV1 蒸馏 608 31.0(+1.6) 下载链接 配置文件 slim配置文件

蒸馏剪裁联合策略

COCO上benchmark

模型 压缩策略 输入尺寸 GFLOPs 模型体积(MB) Box AP 下载 模型配置文件 压缩算法配置文件
YOLOv3-MobileNetV1 baseline 608 24.65 94.6 29.4 下载链接 配置文件 -
YOLOv3-MobileNetV1 蒸馏+剪裁 608 7.54(-69.4%) 32.0(-66.0%) 28.4(-1.0) 下载链接 配置文件 slim配置文件