压缩benchmark

在PaddleDetection, 提供了基于PaddleSlim进行模型压缩的完整教程和实验结果。详细教程请参考:

下面给出压缩的benchmark实验结果。

测试环境

  • Python 2.7.1
  • PaddlePaddle >=1.6
  • CUDA 9.0
  • cuDNN >=7.4
  • NCCL 2.1.2

剪裁模型库

训练策略

  • 剪裁模型训练时使用PaddleDetection模型库发布的模型权重作为预训练权重。
  • 剪裁训练使用模型默认配置,即除pretrained_weights外配置不变。
  • 剪裁模型全部为基于敏感度的卷积通道剪裁。
  • YOLOv3模型主要剪裁yolo_head部分,即剪裁参数如下。
--pruned_params="yolo_block.0.0.0.conv.weights,yolo_block.0.0.1.conv.weights,yolo_block.0.1.0.conv.weights,yolo_block.0.1.1.conv.weights,yolo_block.0.2.conv.weights,yolo_block.0.tip.conv.weights,yolo_block.1.0.0.conv.weights,yolo_block.1.0.1.conv.weights,yolo_block.1.1.0.conv.weights,yolo_block.1.1.1.conv.weights,yolo_block.1.2.conv.weights,yolo_block.1.tip.conv.weights,yolo_block.2.0.0.conv.weights,yolo_block.2.0.1.conv.weights,yolo_block.2.1.0.conv.weights,yolo_block.2.1.1.conv.weights,yolo_block.2.2.conv.weights,yolo_block.2.tip.conv.weights"
  • YOLOv3模型剪裁中剪裁策略r578表示yolo_head中三个输出分支一次使用0.5, 0.7, 0.8的剪裁率剪裁,即剪裁率如下。
--pruned_ratios="0.5,0.5,0.5,0.5,0.5,0.5,0.7,0.7,0.7,0.7,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8"
  • YOLOv3模型剪裁中剪裁策略sensity表示yolo_head中各参数剪裁率如下,该剪裁率为使用yolov3_mobilnet_v1模型在COCO数据集上敏感度实验分析得出。
--pruned_ratios="0.1,0.2,0.2,0.2,0.2,0.1,0.2,0.3,0.3,0.3,0.2,0.1,0.3,0.4,0.4,0.4,0.4,0.3"

YOLOv3 on COCO

骨架网络 剪裁策略 GFLOPs 模型体积(MB) 输入尺寸 Box AP 下载
ResNet50-vd-dcn baseline 44.71 176.82 608 39.1 下载链接
ResNet50-vd-dcn sensity 37.53(-16.06%) 149.49(-15.46%) 608 39.8(+0.7) 下载链接
ResNet50-vd-dcn r578 29.98(-32.94%) 112.08(-36.61%) 608 38.3(-0.8) 下载链接
MobileNetV1 baseline 20.64 94.60 608 29.3 下载链接
MobileNetV1 baseline 9.66 94.60 416 29.3 下载链接
MobileNetV1 baseline 5.72 94.60 320 27.1 下载链接
MobileNetV1 sensity 13.57(-34.27%) 67.60(-28.54%) 608 30.2(+0.9) 下载链接
MobileNetV1 sensity 6.35(-34.27%) 67.60(-28.54%) 416 29.7(+0.4) 下载链接
MobileNetV1 sensity 3.76(-34.27%) 67.60(-28.54%) 320 27.2(+0.1) 下载链接
MobileNetV1 r578 6.27(-69.64%) 31.30(-66.90%) 608 27.8(-1.5) 下载链接
MobileNetV1 r578 2.93(-69.64%) 31.30(-66.90%) 416 26.8(-2.5) 下载链接
MobileNetV1 r578 1.74(-69.64%) 31.30(-66.90%) 320 24.0(-3.1) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用sensity剪裁策略下,YOLOv3-ResNet50-vd-dcnYOLOv3-MobileNetV1分别减少了16.06%34.27%的FLOPs,输入图像尺寸为608时精度分别提高0.70.9
  • 在使用r578剪裁策略下,YOLOv3-ResNet50-vd-dcnYOLOv3-MobileNetV1分别减少了32.98%69.64%的FLOPs,输入图像尺寸为608时精度分别降低0.81.5

YOLOv3 on Pascal VOC

骨架网络 剪裁策略 GFLOPs 模型体积(MB) 输入尺寸 Box AP 下载
MobileNetV1 baseline 20.20 93.37 608 76.2 下载链接
MobileNetV1 baseline 9.46 93.37 416 76.7 下载链接
MobileNetV1 baseline 5.60 93.37 320 75.3 下载链接
MobileNetV1 sensity 13.22(-34.55%) 66.53(-28.74%) 608 78.4(+2.2) 下载链接
MobileNetV1 sensity 6.19(-34.55%) 66.53(-28.74%) 416 78.7(+2.0) 下载链接
MobileNetV1 sensity 3.66(-34.55%) 66.53(-28.74%) 320 76.1(+0.8) 下载链接
MobileNetV1 r578 6.15(-69.57%) 30.81(-67.00%) 608 77.6(+1.4) 下载链接
MobileNetV1 r578 2.88(-69.57%) 30.81(-67.00%) 416 77.7(+1.0) 下载链接
MobileNetV1 r578 1.70(-69.57%) 30.81(-67.00%) 320 75.5(+0.2) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用sensityr578剪裁策略下,YOLOv3-MobileNetV1分别减少了34.55%69.57%的FLOPs,输入图像尺寸为608时精度分别提高2.21.4

蒸馏通道剪裁模型

可通过高精度模型蒸馏通道剪裁后模型的方式,训练方法及相关示例见蒸馏通道剪裁模型

COCO数据集上蒸馏通道剪裁模型库如下。

骨架网络 剪裁策略 GFLOPs 模型体积(MB) 输入尺寸 teacher模型 Box AP 下载
ResNet50-vd-dcn baseline 44.71 176.82 608 - 39.1 下载链接
ResNet50-vd-dcn r578 29.98(-32.94%) 112.08(-36.61%) 608 YOLOv3-ResNet50-vd-dcn(39.1) 39.7(+0.6) 下载链接
MobileNetV1 baseline 20.64 94.60 608 - 29.3 下载链接
MobileNetV1 baseline 9.66 94.60 416 - 29.3 下载链接
MobileNetV1 baseline 5.72 94.60 320 - 27.1 下载链接
MobileNetV1 r578 6.27(-69.64%) 31.30(-66.90%) 608 YOLOv3-ResNet34(36.2) 29.0(-0.3) 下载链接
MobileNetV1 r578 2.93(-69.64%) 31.30(-66.90%) 416 YOLOv3-ResNet34(34.3) 28.0(-1.3) 下载链接
MobileNetV1 r578 1.74(-69.64%) 31.30(-66.90%) 320 YOLOv3-ResNet34(31.4) 25.1(-2.0) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用r578剪裁策略并使用YOLOv3-ResNet50-vd-dcn作为teacher模型蒸馏,YOLOv3-ResNet50-vd-dcn模型减少了32.94%的FLOPs,输入图像尺寸为608时精度提高0.6
  • 在使用r578剪裁策略并使用YOLOv3-ResNet34作为teacher模型蒸馏下,YOLOv3-MobileNetV1模型减少了69.64%的FLOPs,输入图像尺寸为608时精度降低0.3

Pascal VOC数据集上蒸馏通道剪裁模型库如下。

骨架网络 剪裁策略 GFLOPs 模型体积(MB) 输入尺寸 teacher模型 Box AP 下载
MobileNetV1 baseline 20.20 93.37 608 - 76.2 下载链接
MobileNetV1 baseline 9.46 93.37 416 - 76.7 下载链接
MobileNetV1 baseline 5.60 93.37 320 - 75.3 下载链接
MobileNetV1 r578 6.15(-69.57%) 30.81(-67.00%) 608 YOLOv3-ResNet34(82.6) 78.8(+2.6) 下载链接
MobileNetV1 r578 2.88(-69.57%) 30.81(-67.00%) 416 YOLOv3-ResNet34(81.9) 78.7(+2.0) 下载链接
MobileNetV1 r578 1.70(-69.57%) 30.81(-67.00%) 320 YOLOv3-ResNet34(80.1) 76.3(+2.0) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用r578剪裁策略并使用YOLOv3-ResNet34作为teacher模型蒸馏下,YOLOv3-MobileNetV1模型减少了69.57%的FLOPs,输入图像尺寸为608时精度提高2.6

YOLOv3通道剪裁模型推理时延

  • 时延单位均为ms/images
  • Tesla P4时延为单卡并开启TensorRT推理时延
  • 高通835/高通855/麒麟970时延为使用PaddleLite部署,使用arm8架构并使用4线程(4 Threads)推理时延
骨架网络 数据集 剪裁策略 GFLOPs 模型体积(MB) 输入尺寸 Tesla P4 麒麟970 高通835 高通855
MobileNetV1 VOC baseline 20.20 93.37 608 16.556 748.404 734.970 289.878
MobileNetV1 VOC baseline 9.46 93.37 416 9.031 371.214 349.065 140.877
MobileNetV1 VOC baseline 5.60 93.37 320 6.235 221.705 200.498 80.515
MobileNetV1 VOC r578 6.15(-69.57%) 30.81(-67.00%) 608 10.064(-39.21%) 314.531(-57.97%) 323.537(-55.98%) 123.414(-57.43%)
MobileNetV1 VOC r578 2.88(-69.57%) 30.81(-67.00%) 416 5.478(-39.34%) 151.562(-59.17%) 146.014(-58.17%) 56.420(-59.95%)
MobileNetV1 VOC r578 1.70(-69.57%) 30.81(-67.00%) 320 3.880(-37.77%) 91.132(-58.90%) 87.440(-56.39%) 31.470(-60.91%)
ResNet50-vd-dcn COCO baseline 44.71 176.82 608 36.127 - - -
ResNet50-vd-dcn COCO sensity 37.53(-16.06%) 149.49(-15.46%) 608 33.245(-7.98%) - - -
ResNet50-vd-dcn COCO r578 29.98(-32.94%) 112.08(-36.61%) 608 29.138(-19.35%) - - -
  • 在使用r578剪裁策略下,YOLOv3-MobileNetV1模型减少了69.57%的FLOPs,输入图像尺寸为608时在单卡Tesla P4(TensorRT)推理时间减少39.21%,在麒麟970/高通835/高通855上推理时延分别减少57.97%, 55.98%57.43%
  • 在使用sensityr578剪裁策略下,YOLOv3-ResNet50-vd-dcn模型分别减少了16.06%32.94%的FLOPs,输入图像尺寸为608时在单卡Tesla P4(TensorRT)推理时间分别减少7.98%19.35%

蒸馏模型库

训练策略

  • 蒸馏模型训练时teacher模型使用PaddleDetection模型库发布的模型权重作为预训练权重。
  • 蒸馏模型训练时student模型使用backbone的预训练权重
  • 蒸馏策略l2_distiil为使用teacher模型和student模型特征图的L2损失作为蒸馏损失进行蒸馏,为slim/distillation/distill.py的默认策略
  • 蒸馏策略split_distiil为使用YOLOv3细粒度损失进行蒸馏,通过-o use_fine_grained_loss=true指定

YOLOv3 on COCO

骨架网络 蒸馏策略 输入尺寸 teacher模型 Box AP 下载
MobileNetV1 baseline 608 - 29.3 下载链接
MobileNetV1 baseline 416 - 29.3 下载链接
MobileNetV1 baseline 320 - 27.1 下载链接
MobileNetV1 split_distiil 608 YOLOv3-ResNet34(36.2) 31.4(+2.1) 下载链接
MobileNetV1 split_distiil 416 YOLOv3-ResNet34(34.3) 30.0(+0.7) 下载链接
MobileNetV1 split_distiil 320 YOLOv3-ResNet34(31.4) 27.1(+0.0) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用YOLOv3-ResNet34模型通过split_distiil策略蒸馏下,输入图像尺寸为608时YOLOv3-MobileNetV1模型精度提高2.1

YOLOv3 on Pascal VOC

骨架网络 蒸馏策略 输入尺寸 teacher模型 Box AP 下载
MobileNetV1 baseline 608 - 76.2 下载链接
MobileNetV1 baseline 416 - 76.7 下载链接
MobileNetV1 baseline 320 - 75.3 下载链接
MobileNetV1 l2_distiil 608 YOLOv3-ResNet34(82.6) 79.0(+2.8) 下载链接
MobileNetV1 l2_distiil 416 YOLOv3-ResNet34(81.9) 78.2(+1.5) 下载链接
MobileNetV1 l2_distiil 320 YOLOv3-ResNet34(80.1) 75.5(+0.2) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中YOLOv3-MobileNetV1提供了在608/416/320三种不同尺寸下的精度结果
  • 在使用YOLOv3-ResNet34模型通过l2_distiil策略蒸馏下,输入图像尺寸为608时YOLOv3-MobileNetV1模型精度提高2.8

量化模型库

训练策略

  • 量化策略post为使用离线量化得到的模型,aware为在线量化训练得到的模型。

YOLOv3 on COCO

骨架网络 预训练权重 量化策略 输入尺寸 Box AP 下载
MobileNetV1 ImageNet baseline 608 29.3 下载链接
MobileNetV1 ImageNet baseline 416 29.3 下载链接
MobileNetV1 ImageNet baseline 320 27.1 下载链接
MobileNetV1 ImageNet post 608 27.9(-1.4) 下载链接
MobileNetV1 ImageNet post 416 28.0(-1.3) 下载链接
MobileNetV1 ImageNet post 320 26.0(-1.1) 下载链接
MobileNetV1 ImageNet aware 608 28.1(-1.2) 下载链接
MobileNetV1 ImageNet aware 416 28.2(-1.1) 下载链接
MobileNetV1 ImageNet aware 320 25.8(-1.3) 下载链接
ResNet34 ImageNet baseline 608 36.2 下载链接
ResNet34 ImageNet baseline 416 34.3 下载链接
ResNet34 ImageNet baseline 320 31.4 下载链接
ResNet34 ImageNet post 608 35.7(-0.5) 下载链接
ResNet34 ImageNet aware 608 35.2(-1.1) 下载链接
ResNet34 ImageNet aware 416 33.3(-1.0) 下载链接
ResNet34 ImageNet aware 320 30.3(-1.1) 下载链接
R50vd-dcn object365 baseline 608 41.4 下载链接
R50vd-dcn object365 aware 608 40.6(-0.8) 下载链接
R50vd-dcn object365 aware 416 37.5(-) 下载链接
R50vd-dcn object365 aware 320 34.1(-) 下载链接
  • YOLO v3在训练阶段对minibatch采用随机reshape,可以采用相同的模型权重不同尺寸图片,表中部分模型提供了在608/416/320三种不同尺寸下的精度结果
  • YOLOv3-MobileNetV1使用离线(post)和在线(aware)两种量化方式,输入图像尺寸为608时精度分别降低1.41.2
  • YOLOv3-ResNet34使用离线(post)和在线(aware)两种量化方式,输入图像尺寸为608时精度分别降低0.51.1
  • YOLOv3-R50vd-dcn使用在线(aware)量化方式,输入图像尺寸为608时精度降低0.8

BlazeFace on WIDER FACE

模型 量化策略 输入尺寸 Easy Set Medium Set Hard Set 下载
BlazeFace baseline 640 91.5 89.2 79.7 下载链接
BlazeFace post 640 87.8(-3.7) 85.1(-3.9) 74.9(-4.8) 下载链接
BlazeFace aware 640 90.5(-1.0) 87.9(-1.3) 77.6(-2.1) 下载链接
BlazeFace-Lite baseline 640 90.9 88.5 78.1 下载链接
BlazeFace-Lite post 640 89.4(-1.5) 86.7(-1.8) 75.7(-2.4) 下载链接
BlazeFace-Lite aware 640 89.7(-1.2) 87.3(-1.2) 77.0(-1.1) 下载链接
BlazeFace-NAS baseline 640 83.7 80.7 65.8 下载链接
BlazeFace-NAS post 640 81.6(-2.1) 78.3(-2.4) 63.6(-2.2) 下载链接
BlazeFace-NAS aware 640 83.1(-0.6) 79.7(-1.0) 64.2(-1.6) 下载链接
  • BlazeFace系列模型中在线(aware)量化性能明显优于离线(post)量化
  • BlazeFace模型使用在线(aware)量化方式,在Easy/Medium/Hard数据集上精度分别降低1.0, 1.32.1
  • BlazeFace-Lite模型使用在线(aware)量化方式,在Easy/Medium/Hard数据集上精度分别降低1.2, 1.21.1
  • BlazeFace-NAS模型使用在线(aware)量化方式,在Easy/Medium/Hard数据集上精度分别降低0.6, 1.01.6