How to convert .npy file into .binaryproto?

纵饮孤独 提交于 2020-01-21 09:56:04

问题


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 file to train using the GoogLeNet.


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/41503404/how-to-convert-npy-file-into-binaryproto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!