VainF / Torch-Pruning

[CVPR 2023] DepGraph: Towards Any Structural Pruning
https://arxiv.org/abs/2301.12900
MIT License
2.71k stars 334 forks source link

发现yolov8剪枝效果都是每一层是剪枝前一半通道,不是全局权重来剪枝。 #158

Open huangzongmou opened 1 year ago

huangzongmou commented 1 year ago

请教大佬,经过yolov8s经过剪枝0.5后就结构和yolov8n完全一样,这样剪枝有何意义呢,那不是和直接用yolov8n训练一样么?

VainF commented 1 year ago

设置global_pruning=True可能就是您想要的全局剪枝,如果需要手动固定不同层的剪枝率,可以增加一个ch_sparsity_dict字典参数,指定一下层或者Block的剪枝率。

pruner = tp.pruner.MagnitudePruner(
        model.model,
        example_inputs,
        importance=imp,
        global_pruning=true, # <- Global pruning
        iterative_steps=iterative_steps,
        ch_sparsity=0.5,  # remove 50% channels
        ch_sparsity_dict={model.xxx: 0.2, model.xxxxx: 0.5}, # <- different pruning ratios
        ignored_layers=ignored_layers,
        unwrapped_parameters=unwrapped_parameters
    )
huangzongmou commented 1 year ago

好的,我试试,谢谢