基于pytorch的模型压缩和模型剪枝Model Prune示例
生活随笔
收集整理的這篇文章主要介紹了
基于pytorch的模型压缩和模型剪枝Model Prune示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
神經網絡和卷積神經網絡的模型剪枝Model Prune
1,神經網絡和卷積神經網絡模型剪枝方法。
2,可指定剪枝率進行定向剪枝,并輸出剪枝后參數統計和finetune。
3,支持MLP, Lenet, Alexnet, VGG, GoogleNet系列, Resnet系列,MobileNet系列的剪枝。
下載地址:下載地址
#!/usr/bin/env python
# coding: utf-8
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets, transforms
import torch.utils.data
import numpy as np
import math
def to_var(x, requires_grad=False):"""Automatically choose cpu or cuda"""if torch.cuda.is_available():x = x.cuda()return x.clone().detach().requires_grad_(requires_grad)class MaskedConv2d(nn.Conv2d):def __init__(self, in_channels, out_channels, kernel_size, stride=1,padding=0, dilation=1, groups=1, bias=True):super(MaskedConv2
總結
以上是生活随笔為你收集整理的基于pytorch的模型压缩和模型剪枝Model Prune示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (各种均衡算法在MIMO中的应用对比试验
- 下一篇: 原创:抗战时期光芒耀眼的黄埔系,解放战争