-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert binaryproto to npy (like ilsvrc_2012_mean.npy)? #290
Comments
1: For binaryproto/numpy conversion see convert.py and its utility functions. Load the binaryproto in python, yielding a blob, then call 2: The mean would ideally be embedded in the net definition, so that it doesn't need to be carried around elsewhere. There is ongoing work #148 #244 and a planned change to a channel mean that could be easily written in prototxt (that is, each channel would have a space invariant mean value, which has comparable performance to a full image mean and simplifies processing). |
Dear Evan Shelhamer, Thank you for you help! I have read convert.py and found that the function 'blobproto_to_array'. To convert the format, I think it should be: |
The binaryproto file is a protobuf for |
As a tip for people who are reading this now, the file: convert.py does not exist anymore, instead it's function blobproto_to_array moved into the caffe.io module. |
I think @Mezn means the caffe/python/caffe/io.py module |
import caffe
import numpy as np
import sys
if len(sys.argv) != 3:
print "Usage: python convert_protomean.py proto.mean out.npy"
sys.exit()
blob = caffe.proto.caffe_pb2.BlobProto()
data = open( sys.argv[1] , 'rb' ).read()
blob.ParseFromString(data)
arr = np.array( caffe.io.blobproto_to_array(blob) )
out = arr[0]
np.save( sys.argv[2] , out ) |
where are all these files? 404 or doesn't exist now |
The utility functions to read protofiles and to write them into other formats are in the io module. You can find the code here: |
Great thanks to @sg90 for sharing such a nice snippet 👍 |
When I run the pretrained ImageNet model, I found the python wrapper (wrapper.py) will read this file:
python/caffe/imagenet/ilsvrc_2012_mean.npy
To my understanding, the file is the numpy version of file "imagenet_mean.binaryproto".
Thank you!
The text was updated successfully, but these errors were encountered: