簡體   English   中英

“數組形狀不正確。” 從npy轉換為binaryproto時出錯

[英]'Incorrect array shape.' error in converting from npy to binaryproto

我有brainwash_mean.npy文件,它是沒有錯誤的正確文件。

我正在嘗試將npy file to 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:])

有什么事嗎

以下代碼對我有用。

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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM