caffemodel 赋值

import numpy as np
import sys
sys.path.insert(0, '/home/eep/embedeep/caffe/caffe/python')
 
import caffe  #导入caffe
caffe.set_mode_cpu()  #设置为gpu模式
# 载入网络,列出各个层的名字
# input =np.loadtxt('80x1x1.txt',dtype=float)
input = np.load('80x1x1.npy')
# iii=np.ones(224,224,3)
net = caffe.Net('scale.prototxt', caffe.TRAIN)

# cnt_layer_weights = net.params['conv1/scale'][0].data
# print(cnt_layer_weights)

##NCHW
# ss=net.params['Scale1'][0]

ss=np.array([2.0],dtype=float)
net.params['Scale1'][0].data.flat=ss.flat
net.save('scale.caffemodel')
# cnt_layer_weights = net.params['Scale1'][0].data
in_ = input[:,:,:,np.newaxis]
# in_ = input[np.newaxis,np.newaxis,:,np.newaxis]
net.blobs['data'].data[...] = in_
# print("blobs {}\nparams {}".format(net.blobs.keys(), net.params.keys()))
net.forward()
cnt_layer_weights = net.params['Scale1'][0].data
out = net.blobs['out'].data[0]
print(out[0])
np.savetxt('out.txt',out[0],fmt='%d')
print('finshed!')
 

你可能感兴趣的:(算法,AI)