MCPcopy Create free account
hub / github.com/NVIDIA/DALI / batch_to_numpy

Function batch_to_numpy

dali/python/nvidia/dali/_utils/external_source_impl.py:145–164  ·  view source on GitHub ↗
(
    batch,
    error_str="Unsupported callback return type. Got: `{}`.",
    non_uniform_str="Uniform input is required (batch of tensors of equal shapes), got {}.",
)

Source from the content-addressed store, hash-verified

143
144
145def batch_to_numpy(
146 batch,
147 error_str="Unsupported callback return type. Got: `{}`.",
148 non_uniform_str="Uniform input is required (batch of tensors of equal shapes), got {}.",
149):
150 import_numpy()
151 assert_cpu_batch_data_type(batch, error_str)
152 if isinstance(batch, tensors.TensorListCPU):
153 if not batch.is_dense_tensor():
154 raise ValueError(non_uniform_str.format(batch))
155 return batch.as_array()
156 elif isinstance(batch, list):
157 result = [sample_to_numpy(sample, error_str) for sample in batch]
158 first_shape = result[0].shape
159 for sample in result:
160 if first_shape != sample.shape:
161 raise ValueError(non_uniform_str.format(batch))
162 return np.stack(result)
163 else:
164 return sample_to_numpy(batch, error_str)
165
166
167class _CycleIter:

Callers 4

_inspect_dataFunction · 0.85
__next__Method · 0.85
__next__Method · 0.85
__next__Method · 0.85

Calls 4

sample_to_numpyFunction · 0.85
stackMethod · 0.80
import_numpyFunction · 0.70

Tested by

no test coverage detected