MCPcopy Create free account
hub / github.com/BVLC/caffe / blobproto_to_array

Function blobproto_to_array

python/caffe/io.py:18–34  ·  view source on GitHub ↗

Convert a blob proto to an array. In default, we will just return the data, unless return_diff is True, in which case we will return the diff.

(blob, return_diff=False)

Source from the content-addressed store, hash-verified

16
17## proto / datum / ndarray conversion
18def blobproto_to_array(blob, return_diff=False):
19 """
20 Convert a blob proto to an array. In default, we will just return the data,
21 unless return_diff is True, in which case we will return the diff.
22 """
23 # Read the data into an array
24 if return_diff:
25 data = np.array(blob.diff)
26 else:
27 data = np.array(blob.data)
28
29 # Reshape the array
30 if blob.HasField('num') or blob.HasField('channels') or blob.HasField('height') or blob.HasField('width'):
31 # Use legacy 4D shape
32 return data.reshape(blob.num, blob.channels, blob.height, blob.width)
33 else:
34 return data.reshape(blob.shape.dim)
35
36def array_to_blobproto(arr, diff=None):
37 """Converts a N-dimensional array to blob proto. If diff is given, also

Callers 1

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected