Skip to content

Commit

Permalink
make python wrapper mean match binaryproto dimensions
Browse files Browse the repository at this point in the history
ilsvrc_2012_mean.npy has dims K x H x W.

Code written for the old D x D x K mean needs to be rewritten!
  • Loading branch information
shelhamer committed May 14, 2014
1 parent 51f276e commit 47ec9ac
Showing 1 changed file with 0 additions and 0 deletions.
Binary file modified python/caffe/imagenet/ilsvrc_2012_mean.npy
Binary file not shown.

1 comment on commit 47ec9ac

@wendlerc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be useful for somebody.

from caffe.proto import caffe_pb2
from caffe.io import blobproto_to_array
import numpy as np

def convertAndStore(binaryproto_file_path, npy_file_path):
    blob = caffe_pb2.BlobProto()
    data = open(binaryproto_file_path, "rb").read()
    blob.ParseFromString(data)
    nparray = blobproto_to_array(blob)
    #the blob is in blob format batchsize,channels,height,width
    #crop the first dim -> image
    #TODO: ? the provided .npy file of caffe ranges from 0-255 -> *255
    nparray = nparray[0]
    try:
        f = file(npy_file_path,"wb")
        np.save(f,nparray)
        f.close()
    except:
        print "save nparray to file %s error!" % npy_file_path

def convert(binaryproto_file_path):
    blob = caffe_pb2.BlobProto()
    data = open(binaryproto_file_path, "rb").read()
    blob.ParseFromString(data)
    nparray = blobproto_to_array(blob)
    #the blob is in blob format batchsize,channels,height,width
    #crop the first dim -> image
    #TODO: ? the provided .npy file of caffe ranges from 0-255 -> *255
    nparray = nparray[0]
    return nparray

Please sign in to comment.