pytorch distiller filter channel剪枝

Pruning Filters and Channels - Neural Network Distillerhttps://intellabs.github.io/distiller/tutorial-struct_pruning.htmlDistiller tutorial: Pruning Filters & Channels_koberonaldo24的博客-CSDN博客本文为对distiller教程 Pruning Filters & Channels 的翻译。原文地址:Pruning Filters & ChannelsIntroductionchannel和filter的剪枝是结构化剪枝的示例,这些剪枝方法不需要特殊硬件即可完成剪枝并压缩模型,这也使得这种剪枝方法非常有趣并广泛应用。在具有串行数据依赖性的网络中,很容易理解和定义如何修建...https://blog.csdn.net/koberonaldo24/article/details/102939434深度学习笔记_基本概念_卷积网络中的通道channel、特征图feature map、过滤器filter和卷积核kernel_惊鸿一博-CSDN博客目录卷积网络中的通道、特征图、过滤器和卷积核1.feature map1.1 feature map1.2 feature map怎么生成的?1.3 多个feature map 的作用是什么?2.卷积核2.1 定义2.2 形状2.3卷积核个数的理解3.filter4.channel4.1 定义4.2 分类4.3 通道与特征4.4通道的终点卷积网络中的通道、特征图、过滤器和卷积核1.feature map1.1 feature map.https://visionary.blog.csdn.net/article/details/108048264?utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-1.no_search_link模型通道剪枝汇总(channel pruning)_三寸光阴___的博客-CSDN博客_通道剪枝https://blog.csdn.net/qq_38109843/article/details/107462887

pytorch Resnet50分类模型剪枝_三寸光阴___的博客-CSDN博客_resnet50剪枝Resnet50网络结构:https://www.jianshu.com/p/993c03c22d52剪枝方式1.基于network-slimming论文的方法:pytorch版代码:https://github.com/Eric-mingjie/network-slimming思路:去掉downsample里面的BN层,为了方便采用Resnetv2的结构:BN-Conv-ReLU,在每一个bottleneck的第一个BN后自定义一个通道选择层(全1层),训练过程中不影响,剪枝时先生成BN的通道mahttps://blog.csdn.net/qq_38109843/article/details/107671873YOLOv3模型剪枝_三寸光阴___的博客-CSDN博客_yolov3剪枝参考代码:https://github.com/Lam1360/YOLOv3-model-pruninghttps://github.com/coldlarry/YOLOv3-complete-pruning剪枝代码解读:https://blog.csdn.net/just_sort/article/details/107089710剪枝原理:https://openaccess.thecvf.com/content_iccv_2017/html/Liu_Learning_Efficient_Convhttps://blog.csdn.net/qq_38109843/article/details/107234801

一.filter剪枝

1.串行模型filter剪枝

        In filter pruning we use some criterion to determine which filters are important and which are not. Researchers came up with all sorts of pruning criteria: the L1-magnitude of the filters (citation), the entropy of the activations (citation), and the classification accuracy reduction (citation) are just some examples. Disregarding how we chose the filters to prune, let’s imagine that in the diagram below, we chose to prune (remove) the green and orange filters (the circle with the “*” designates a Convolution operation).

        filter剪枝使用一些标准决定filter是否重要。各种各样的标准包括:filter的L1,激活的熵,分类准确率下降。假设绿色和橘色filter需要移除。

Example 1

pruners: example_pruner:

        class: L1RankedStructureParameterPruner_AGP

                initial_sparsity : 0.10

                final_sparsity: 0.50

                group_type: Filters

                weights: [module.conv1.weight]

        Distiller detects the presence of Batch Normalization layers and adjusts their parameters automatically.

2.自动调整batchnorm层结构

distiller能自动检测批归一化层的存在,自动调整批归一化的参数。

Example 2

3.并行结构剪枝

3.1和串行结构一样

Example 3

pruners: example_pruner:

        class: L1RankedStructureParameterPruner_AGP

                initial_sparsity : 0.10

                final_sparsity: 0.50

                group_type: Filters

                weights: [module.conv1.weight]

3.2自行修改

Example 5

 pruners: example_pruner:

         class: L1RankedStructureParameterPruner_AGP

                initial_sparsity : 0.10

                final_sparsity: 0.50

                group_type: Filters

                group_dependency: Leader

                 weights: [module.conv1.weight, module.conv2.weight]

二.通道剪枝

Example 1

            一个卷积层包含F个filter,每个filter包含C个高度为H宽度为W的Channel。卷积层权重张量尺寸为HxWxCxF。 图中方块代表一个filter,每个方块找那个的分片,代表一个channel。减少conv1的filter会减少输出通道,distiller能自动减少conv2的channel.反之,减少conv2的channel,distiller会自动减少conv1的filter。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
pytorch是一种开源的机器学习框架,它提供了一套丰富的工具和算法,方便用户构建和训练深度学习模型。其中的bn剪枝技术是一种用于减少深度学习模型的冗余度和计算复杂度的方法。 在pytorch中,使用bn剪枝技术可以通过删除不重要的神经元或层来减少模型的规模。首先,我们需要使用训练数据对模型进行训练,然后使用评估数据对模型进行评估。通过计算评估数据上的损失函数,可以获得每个层中神经元的重要性。根据重要性分数,我们可以选择保留最重要的神经元,并删除那些对模型没有显著影响的神经元。 具体的实现过程可以通过使用pytorch提供的函数和类来完成。首先,我们可以使用pytorch的BN层来构建模型,并使用标准的反向传播算法对模型进行训练。然后,使用pytorch的评估函数对模型进行评估,并计算每个层中神经元的重要性分数。根据重要性分数,我们可以使用pytorch剪枝函数来删除不重要的神经元或层。 使用pytorch对模型进行bn剪枝可以达到减少模型规模和计算复杂度的效果。减少模型规模可以降低存储和计算资源的需求,使模型在部署和运行时更加高效。而减少计算复杂度可以加快模型的训练和推理速度,提高模型的实时性和效率。 总而言之,pytorch对模型的bn剪枝提供了简单且高效的方法,可以帮助用户减少模型规模和计算复杂度,提高深度学习模型的性能和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值