概述
模型压缩是在计算资源有限且能耗紧张的移动设备上,有效部署神经网络模型的关键技术。 传统的模型压缩技术依赖于手工制作的启发式和基于规则的策略,这需要领域专家探索在模型大小、速度和准确性之间进行权衡的大型设计空间,这通常是次优且耗时的。 在本文中,我们利用强化学习来提供模型压缩策略。
这种基于学习的压缩策略优于传统的基于规则的压缩策略,具有更高的压缩比、更好地保持准确性和解放人力。 在 4 倍 FLOPs 减少的情况下,我们在 ImageNet 上实现了比 VGG-16 的手工模型压缩策略高 2.7% 的准确度。 我们将这种自动化的一键式压缩管道应用于 MobileNet,在 Android 手机上实现了 1.81 倍的测量推理延迟加速,在 Titan XP GPU 上实现了 1.43 倍的加速,ImageNet Top-1 精度仅损失 0.1%。
模型压缩介绍
简述:对比传统模型压缩,针对不同的场景提出了两种压缩策略搜索协议。
卷积神经网络压缩和加速
简述:神经网络压缩对象和效率。实现模型压缩引擎。使用强化学习进行自动压缩。搜索协议:资源约束压缩;精度保证压缩。
import torch.nn as nn
import math
def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp, oup, 3, stride, 1, bias=False),
nn.BatchNorm2d(oup),
nn.ReLU(inplace=True)
)
def conv_dw(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp, inp, 3, stride, 1, groups=inp, bias=False),
nn.BatchNorm2d(inp),
nn.ReLU(inplace=True),
nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
nn.BatchNorm2d(oup),
nn.ReLU(inplace=True),
)
class MobileNet(nn.Module):
def __init__(self, n_class, profile='normal'):
super(MobileNet, self).__init__()
# original
if profile == 'normal':
in_planes = 32
cfg = [64, (128, 2), 128, (256, 2), 256, (512, 2), 512, 512, 512, 512, 512, (1024, 2), 1024]
# 0.5 AMC
elif profile == '0.5flops':
in_planes = 24
cfg = [48, (96, 2), 80, (192, 2), 200, (328, 2), 352, 368, 360, 328, 400, (736, 2), 752]
else:
raise NotImplementedError
self.conv1 = conv_bn(3, in_planes, stride=2)
self.features = self._make_layers(in_planes, cfg, conv_dw)
self.classifier = nn.Sequential(
nn.Linear(cfg[-1], n_class),
)
self._initialize_weights()
测试
简述:CIFAR-10 和分析:FLOPs-约束压缩;精度保证压缩。加速策略探索。ImageNet:突破细粒度修剪的极限;与启发式通道缩减的比较;加速移动端推理;泛化能力。
源代码
详情参阅 亚图跨际