hans

hans

【Python】【Caffe】三、生成.npy均值文件《python调用caffe模块》


GitHub 代码地址: https://github.com/HansRen1024/Use-Python-to-call-Caffe-module

前言#

我们一般都会用 caffe 提供的 make_mean.sh 生成 prototxt 格式的均值文件,并且这个脚本最后也会在终端输出三个均值。

下面代码就是如果将 prototxt 或者均值转换成.npy 格式的均值文件。

一、prototxt 转换为 npy#

import caffe
import numpy as np

prototxt = 'doc/mean.binaryproto'
npy = 'doc/mean.npy'

blob = caffe.proto.caffe_pb2.BlobProto()
data = open(prototxt, 'rb' ).read()
blob.ParseFromString(data)

array = np.array(caffe.io.blobproto_to_array(blob))
mean_npy = array[0]
np.save(npy ,mean_npy)

二、均值转换为 npy#

import numpy as np

npy = 'doc/mean.npy'

mean = np.ones([3,256, 256], dtype=np.float) #256是图像尺寸
mean[0,:,:] = 100
mean[1,:,:] = 110
mean[2,:,:] = 120

np.save(npy, mean)

以上内容参考自: http://blog.csdn.net/hyman_yx/article/details/51732656

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.