def __init__(self, model_file, weights_file, mean_file):
if not os.path.exists(model_file) or \
not os.path.exists(weights_file) or \
not os.path.exists(mean_file):
raise ValueError('Invalid model: {}, \nweights file: {}, \nmean file: {}'
.format(model_file, weights_file, mean_file))
# Init caffe with model
self.net_ = caffe.Net(model_file, weights_file, caffe.TEST)
self.mean_file_ = mean_file
self.input_shape_ = self.net_.blobs['data'].data.shape
# Initialize mean file
blob_meanfile = caffe.proto.caffe_pb2.BlobProto()
data_meanfile = open(mean_file , 'rb' ).read()
blob_meanfile.ParseFromString(data_meanfile)
meanfile = np.squeeze(np.array(caffe.io.blobproto_to_array(blob_meanfile)))
self.meanfile_ = meanfile.transpose((1,2,0))
self.meanfile_image_ = None
评论列表
文章目录