• 大小: 1.75KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-03-27
  • 语言: 其他
  • 标签: 其他  

资源简介


将caffemodel中小于给定阈值的连接全部置0,如果用CSC等格式存储,会降低存储空间

资源截图

代码片段和文件信息

# coding:utf-8
# by chen yh

import caffe
import numpy as np
import matplotlib.pyplot as plt

def weight_0(prototxtmodellayerthreshold):
    caffe.set_mode_gpu()
    net=caffe.Net(prototxtmodelcaffe.TEST)
    weight = net.params[layer][0].data
    bias = net.params[layer][1].data

    sum_l1=[]
    for i in range(weight.shape[0]):
        for j in range(weight.shape[1]):
            sum_l1.append((ijnp.sum(abs(weight[ij::]))))#i是核的顺序j是每个卷积核与前面某个channel的连接顺序求出每个连接的类似于L1范数的权重和加上ij是为了后续判断weight的时候好直接处理到原weight

    display(sum_l1128)#从小到大排序后打印出前128个L1范数

    l1_plot(sum_l1)#画出L1范数关于out*input的坐标图以确定多少个需要修剪.

    weight_l1 = []
    for i in sum_l1:
        weight_l1.append(i[2]) #得到仅含有l1范数的列表
    for iweight_sum in enumerate(weight_l1):
        if weight_sum < thresho

评论

共有 条评论