Python caffe.proto.caffe_pb2.BlobProto() Examples
The following are 20
code examples of caffe.proto.caffe_pb2.BlobProto().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
caffe.proto.caffe_pb2
, or try the search function
.
Example #1
Source File: pickle_caffe_blobs.py From masktextspotter.caffe2 with Apache License 2.0 | 5 votes |
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])
Example #2
Source File: convert.py From tensorflow-resnet with MIT License | 5 votes |
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))
Example #3
Source File: io.py From TF2 with Apache License 2.0 | 5 votes |
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
Example #4
Source File: io.py From TF2 with Apache License 2.0 | 5 votes |
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
Example #5
Source File: pickle_caffe_blobs.py From NucleiDetectron with Apache License 2.0 | 5 votes |
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])
Example #6
Source File: pickle_caffe_blobs.py From CBNet with Apache License 2.0 | 5 votes |
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])
Example #7
Source File: pickle_caffe_blobs.py From Detectron-DA-Faster-RCNN with Apache License 2.0 | 5 votes |
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])
Example #8
Source File: pickle_caffe_blobs.py From Detectron with Apache License 2.0 | 5 votes |
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])
Example #9
Source File: io.py From Deep-Learning-Based-Structural-Damage-Detection with MIT License | 5 votes |
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
Example #10
Source File: pickle_caffe_blobs.py From Detectron-Cascade-RCNN with Apache License 2.0 | 5 votes |
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])
Example #11
Source File: pickle_caffe_blobs.py From KL-Loss with Apache License 2.0 | 5 votes |
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])
Example #12
Source File: io.py From mix-and-match with MIT License | 5 votes |
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
Example #13
Source File: pickle_caffe_blobs.py From seg_every_thing with Apache License 2.0 | 5 votes |
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])
Example #14
Source File: pickle_caffe_blobs.py From Clustered-Object-Detection-in-Aerial-Image with Apache License 2.0 | 5 votes |
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])
Example #15
Source File: example.py From hocrux with Apache License 2.0 | 4 votes |
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
Example #16
Source File: rasterize_jon_scratch.py From hocrux with Apache License 2.0 | 4 votes |
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
Example #17
Source File: example.py From hocrux with Apache License 2.0 | 4 votes |
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
Example #18
Source File: rasterize.py From hocrux with Apache License 2.0 | 4 votes |
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
Example #19
Source File: rasterize_jon_scratch.py From hocrux with Apache License 2.0 | 4 votes |
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
Example #20
Source File: example.py From hocrux with Apache License 2.0 | 4 votes |
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