1

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.

25b3nk
  • 164
  • 2
  • 16

2 Answers2

2

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())
Kev1n91
  • 3,553
  • 8
  • 46
  • 96
1

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())
Harsh Wardhan
  • 2,110
  • 10
  • 36
  • 51