2017-02-17 1 views
0

Ich habe brainwash_mean.npy Datei und es ist eine korrekte Datei ohne Fehler.'Falsche Array-Form.' Fehler bei der Konvertierung von Npy zu binärproto

Ich versuche, die zu konvertieren, und ich habe 'Incorrect array shape.' Fehler.

Mein Code ist

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

Was könnte falsch sein?

Antwort

0

Der folgende Code funktionierte für mich.

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