一、numpy数组生成npy文件
import numpy as np
mean = np.ones([3, 256, 256], dtype=np.float)
mean[0,:,:] = 128 #通道一均值为128
mean[1,:,:] = 129 #通道二均值为129
mean[2,:,:] = 130 #通道三均值为130
np.save("mean.npy", mean)
二、使用npy文件
import numpy as np
mean_npy = np.load("mean.npy")
mean = mean_npy.mean(1).mean(1)
三、npy文件生成binaryprot文件
import caffe
import numpy as np
mean_npy = np.load("mean.npy")
blob = caffe.io.array_to_blobproto(mean_npy)
mean_binproto = "mean.binaryproto"
with open(mean_binproto, 'wb') as f:
f.write(blob.SerialToString())
参考:
1、https://stackoverflow.com/questions/41503404/how-to-convert-npy-file-into-binaryproto