环境
- python 3.9
- numpy 1.24.1
- pytorch 2.0.0+cu117
非结构剪枝
-
特点
1.简单,将满足某些田间的 weight 置为0即可
2.pytorch容易访问所有参数(weight)
3.最精细化
-
类型
1.细粒度剪枝(fine-grained)
2.向量剪枝(vector-level)
3.卷积核剪枝(kernel-level)
一、细粒度剪枝(fine-grained)
学习代码:
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import numpy as np
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.my_layers = nn.Sequential(
# 第一层卷积
nn.Conv2d(3, 64, kernel_size=3, padding=1), #