Python ';数组形状不正确。';从npy转换为binaryproto时出错

Python ';数组形状不正确。';从npy转换为binaryproto时出错,python,numpy,Python,Numpy,我有brainwash\u mean.npy文件,它是一个正确的文件,没有错误 我正在尝试将npy文件转换为binaryproto,我发现的数组形状不正确。错误 我的代码是 def convert_numpy_binaryproto(filename): print filename; avg_img = np.load(filename); #avg_img is your numpy array with the average data blob = ca

我有
brainwash\u mean.npy
文件,它是一个正确的文件,没有错误

我正在尝试将
npy文件转换为binaryproto
,我发现
的数组形状不正确。
错误

我的代码是

def convert_numpy_binaryproto(filename):
    print filename;
    avg_img = np.load(filename);
    #avg_img is your numpy array with the average data 
    blob = caffe.io.array_to_blobproto( avg_img);
    with open( mean.binaryproto, 'wb' ) as f :
        f.write( blob.SerializeToString())


def main(argv):
    convert_numpy_binaryproto(sys.argv[1]);


if __name__ == "__main__":
   main(sys.argv[1:])

有什么问题吗?

下面的代码对我有效

def convert_numpy_binaryproto(path):
    print path;
    avg_img = np.load(path);
    #avg_img is your numpy array with the average data 
    blob = caffe.proto.caffe_pb2.BlobProto();
    blob.channels, blob.height, blob.width = avg_img.shape;
    blob.data.extend(avg_img.astype(float).flat);
    binaryproto_file = open('mean.binaryproto', 'wb' );
    binaryproto_file.write(blob.SerializeToString());
    binaryproto_file.close();