How to convert .npy file into .binaryproto?

后端 未结 2 905
天涯浪人
天涯浪人 2021-01-16 04:34

I have created a mean image file using python and saved it into numpy file. I would like to know how I could convert this .npy file into .binaryproto file. I am using this f

相关标签:
2条回答
  • 2021-01-16 04:48

    You can simply use numpy to creat the .binaryproto and the given caffe io functions

    import caffe
    #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())
    
    0 讨论(0)
  • 2021-01-16 05:11

    Here's an improved version of @Kev1n91's code.

    import caffe
    import numpy as np
    
    mean_npy = np.load('mean.npy') # Input numpy array
    blob = caffe.io.array_to_blobproto(mean_npy)
    mean_binproto = 'mean.binaryproto' # Output binaryproto file
    with open(mean_binproto, 'wb') as f :
        f.write( blob.SerializeToString())
    
    0 讨论(0)
提交回复
热议问题