通道剪枝技术加速深度神经网络
Channel Pruning 项目开发了一种通道剪枝技术,用于加速深度神经网络。该技术显著提高了 VGG-16、ResNet-50 等模型的推理速度,同时保持了较高准确率。项目还包含针对 Faster R-CNN 的剪枝方法,为计算机视觉任务提供了高效解决方案。具体实现了 VGG-16 模型 4 倍和 5 倍的加速,ResNet-50 模型 2 倍加速,以及 Faster R-CNN 2 倍和 4 倍加速。这些优化后的模型在 ImageNet 分类和目标检测任务上仍保持了较高性能。项目提供了代码和预训练模型,方便研究者复现实验结果。
GitHub - yihui-he/channel-pruning: 通道剪枝以加速超深度神经网络 (ICCV'17)
请查看我们在压缩深度模型方面的新作品:
在这个代码库中,我们发布了以下模型的代码:
模型 | 加速比 | 准确率 |
---|---|---|
https://github.com/yihui-he/channel-pruning/releases/tag/channel_pruning_5x | 5倍 | 88.1 (Top-5), 67.8 (Top-1) |
https://github.com/yihui-he/channel-pruning/releases/tag/VGG-16_3C4x | 4倍 | 89.9 (Top-5), 70.6 (Top-1) |
https://github.com/yihui-he/channel-pruning/releases/tag/ResNet-50-2X | 2倍 | 90.8 (Top-5), 72.3 (Top-1) |
https://github.com/yihui-he/channel-pruning/releases/tag/faster-RCNN-2X4X | 2倍 | 36.7 (AP@.50:.05:.95) |
https://github.com/yihui-he/channel-pruning/releases/tag/faster-RCNN-2X4X | 4倍 | 35.1 (AP@.50:.05:.95) |
3C方法结合了空间分解(使用低秩展开加速卷积神经网络)和通道分解(加速用于分类和检测的超深度卷积网络)(在4.1.2节中提到)
如果您在研究中发现这些代码有用,请考虑引用:
@InProceedings{He_2017_ICCV,
author = {He, Yihui and Zhang, Xiangyu and Sun, Jian},
title = {Channel Pruning for Accelerating Very Deep Neural Networks},
booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
month = {Oct},
year = {2017}
}
scipy
、sklearn
、easydict
,使用sudo pip3 install
安装。克隆代码库
# 确保使用--recursive克隆 git clone --recursive https://github.com/yihui-he/channel-pruning.git
构建我的Caffe分支(支持双三次插值和将图像较短边调整为256然后裁剪到224x224)
cd caffe # 如果您熟悉Caffe并已安装所有要求,只需执行: make all -j8 && make pycaffe # 或按照Caffe安装说明进行操作: # http://caffe.berkeleyvision.org/installation.html # 如果您之前已经有了caffe,可能需要将pycaffe添加到PYTHONPATH
下载ImageNet分类数据集 http://www.image-net.org/download-images
在temp/vgg.prototxt
中指定imagenet source
路径(第12行和第36行)
为了快速测试,您可以直接下载已剪枝的模型。请参见[下一节](https://github.com/ethanhe42/channel-pruning/blob/master/about:blank#pruned-models-for-download 1. 下载原始VGG-16模型 http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
将其移动到temp/vgg.caffemodel
(或创建一个软链接)
python3 train.py -action c3 -caffe [GPU0] # 或者使用 ./run.sh python3 train.py -action c3 -caffe [GPU0] 进行日志记录 # 将 [GPU0] 替换为实际的 GPU 设备,如 0、1 或 2
合并一些分解后的层以进一步压缩,并计算加速比。将 temp/cb_3c_3C4x_mem_bn_vgg.prototxt
中的 ImageData 层替换为 [temp/vgg.prototxt
中的相应部分。执行 Shell ./combine.sh | xargs ./calflop.sh
微调
caffe train -solver temp/solver.prototxt -weights temp/cb_3c_vgg.caffemodel -gpu [GPU0,GPU1,GPU2,GPU3] # 将 [GPU0,GPU1,GPU2,GPU3] 替换为实际的 GPU 设备,如 0,1,2,3
虽然在微调过程中会进行测试,但你可以随时使用以下命令进行测试:
caffe test -model path/to/prototxt -weights path/to/caffemodel -iterations 5000 -gpu [GPU0] # 将 [GPU0] 替换为实际的 GPU 设备,如 0、1 或 2
剪枝模型(可下载)
为快速测试,你可以直接从发布页面下载剪枝后的模型:VGG-16 3C 4X、VGG-16 5X、ResNet-50 2X。或者使用百度网盘下载链接
使用以下命令进行测试:
caffe test -model channel_pruning_VGG-16_3C4x.prototxt -weights channel_pruning_VGG-16_3C4x.caffemodel -iterations 5000 -gpu [GPU0]
# 将 [GPU0] 替换为实际的 GPU 设备,如 0、1 或 2
为快速测试,你可以直接从发布页面下载剪枝后的模型。或者你可以:1. 克隆我的 py-faster-rcnn 仓库:https://github.com/yihui-he/py-faster-rcnn 2. 使用本仓库中的剪枝模型来训练 Faster RCNN 2X、4X,solver prototxt 文件在 https://github.com/yihui-he/py-faster-rcnn/tree/master/models/pascal_voc
你可以在我们的 Github wiki 中找到一些常见问题的答案,或者直接创建新的 issue