資源簡(jiǎn)介
將caffemodel中小于給定閾值的連接全部置0,如果用CSC等格式存儲(chǔ),會(huì)降低存儲(chǔ)空間
代碼片段和文件信息
#?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是每個(gè)卷積核與前面某個(gè)channel的連接順序求出每個(gè)連接的類似于L1范數(shù)的權(quán)重和加上ij是為了后續(xù)判斷weight的時(shí)候好直接處理到原weight
????display(sum_l1128)#從小到大排序后打印出前128個(gè)L1范數(shù)
????l1_plot(sum_l1)#畫出L1范數(shù)關(guān)于out*input的坐標(biāo)圖以確定多少個(gè)需要修剪.
????weight_l1?=?[]
????for?i?in?sum_l1:
????????weight_l1.append(i[2])?#得到僅含有l(wèi)1范數(shù)的列表
????for?iweight_sum?in?enumerate(weight_l1):
????????if?weight_sum?
評(píng)論
共有 條評(píng)論