2017-02-17 6 views
0

brainwash_mean.npyファイルがありますが、エラーなしで正しいファイルです。'不正な配列形状です。' npyからbinaryprotoに変換する際にエラーが発生しました

npy file to binaryprotoを変換しようとしていますが、'Incorrect array shape.'エラーがあります。

私のコードが間違っている可能性が何

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:]) 

のですか?

答えて

0

次のコードは私にとって役に立ちました。

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(); 
関連する問題