MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / _batch_numpy

Method _batch_numpy

tensorpack/dataflow/common.py:129–155  ·  view source on GitHub ↗
(data_list)

Source from the content-addressed store, hash-verified

127
128 @staticmethod
129 def _batch_numpy(data_list):
130 data = data_list[0]
131 if isinstance(data, six.integer_types):
132 dtype = 'int32'
133 elif type(data) == bool:
134 dtype = 'bool'
135 elif type(data) == float:
136 dtype = 'float32'
137 elif isinstance(data, (six.binary_type, six.text_type)):
138 dtype = 'str'
139 else:
140 try:
141 dtype = data.dtype
142 except AttributeError:
143 raise TypeError("Unsupported type to batch: {}".format(type(data)))
144 try:
145 return np.asarray(data_list, dtype=dtype)
146 except Exception as e: # noqa
147 logger.exception("Cannot batch data. Perhaps they are of inconsistent shape?")
148 if isinstance(data, np.ndarray):
149 s = pprint.pformat([x.shape for x in data_list])
150 logger.error("Shape of all arrays to be batched: " + s)
151 try:
152 # open an ipython shell if possible
153 import IPython as IP; IP.embed() # noqa
154 except ImportError:
155 pass
156
157 @staticmethod
158 def aggregate_batch(data_holder, use_list=False):

Callers 1

aggregate_batchMethod · 0.80

Calls 2

formatMethod · 0.80
embedMethod · 0.80

Tested by

no test coverage detected