本文整理汇总了Python中caffe.proto.caffe_pb2.BlobProto方法的典型用法代码示例。如果您正苦于以下问题:Python caffe_pb2.BlobProto方法的具体用法?Python caffe_pb2.BlobProto怎么用?Python caffe_pb2.BlobProto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe.proto.caffe_pb2
的用法示例。
在下文中一共展示了caffe_pb2.BlobProto方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_missing_biases
# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 别名]
def add_missing_biases(caffenet_weights):
for layer in caffenet_weights.layer:
if layer.type == 'Convolution' and len(layer.blobs) == 1:
num_filters = layer.blobs[0].shape.dim[0]
bias_blob = caffe_pb2.BlobProto()
bias_blob.data.extend(np.zeros(num_filters))
bias_blob.num, bias_blob.channels, bias_blob.height = 1, 1, 1
bias_blob.width = num_filters
layer.blobs.extend([bias_blob])
示例2: array_to_blobproto
# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 别名]
def array_to_blobproto(arr, diff=None):
"""Converts a 4-dimensional array to blob proto. If diff is given, also
convert the diff. You need to make sure that arr and diff have the same
shape, and this function does not do sanity check.
"""
if arr.ndim != 4:
raise ValueError('Incorrect array shape.')
blob = caffe_pb2.BlobProto()
blob.num, blob.channels, blob.height, blob.width = arr.shape
blob.data.extend(arr.astype(float).flat)
if diff is not None:
blob.diff.extend(diff.astype(float).flat)
return blob
示例3: array_to_blobproto
# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 别名]
def array_to_blobproto(arr, diff=None):
"""Converts a N-dimensional array to blob proto. If diff is given, also
convert the diff. You need to make sure that arr and diff have the same
shape, and this function does not do sanity check.
"""
blob = caffe_pb2.BlobProto()
blob.shape.dim.extend(arr.shape)
blob.data.extend(arr.astype(float).flat)
if diff is not None:
blob.diff.extend(diff.astype(float).flat)
return blob
示例4: load_mean_bgr
# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 别名]
def load_mean_bgr():
""" bgr mean pixel value image, [0, 255]. [height, width, 3] """
with open("data/ResNet_mean.binaryproto", mode='rb') as f:
data = f.read()
blob = caffe_pb2.BlobProto()
blob.ParseFromString(data)
mean_bgr = caffe.io.blobproto_to_array(blob)[0]
assert mean_bgr.shape == (3, 224, 224)
return mean_bgr.transpose((1, 2, 0))
示例5: get_transformer
# 需要导入模块: from caffe.proto import caffe_pb2 [as 别名]
# 或者: from caffe.proto.caffe_pb2 import BlobProto [as 别名]
def get_transformer(deploy_file, mean_file=None):
"""
Returns an instance of caffe.io.Transformer
Arguments:
deploy_file -- path to a .prototxt file
Keyword arguments:
mean_file -- path to a .binaryproto file (optional)
"""
network = caffe_pb2.NetParameter()
with open(deploy_file) as infile:
text_format.Merge(infile.read(), network)
dims = network.input_dim
t = caffe.io.Transformer(
inputs = {'data': dims}
)
t.set_transpose('data', (2,0,1)) # transpose to (channels, height, width)
# color images
if dims[1] == 3:
# channel swap
t.set_channel_swap('data', (2,1,0))
if mean_file:
# set mean pixel
with open(mean_file) as infile:
blob = caffe_pb2.BlobProto()
blob.MergeFromString(infile.read())
if blob.HasField('shape'):
blob_dims = blob.shape
assert len(blob_dims) == 4, 'Shape should have 4 dimensions - shape is "%s"' % blob.shape
elif blob.HasField('num') and blob.HasField('channels') and \
blob.HasField('height') and blob.HasField('width'):
blob_dims = (blob.num, blob.channels, blob.height, blob.width)
else:
raise ValueError('blob does not provide shape or 4d dimensions')
pixel = np.reshape(blob.data, blob_dims[1:]).mean(1).mean(1)
t.set_mean('data', pixel)
return t