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

Function sample_to_numpy

dali/python/nvidia/dali/_utils/external_source_impl.py:121–142  ·  view source on GitHub ↗
(sample, error_str="Unsupported callback return type. Got: `{}`.")

Source from the content-addressed store, hash-verified

119
120
121def sample_to_numpy(sample, error_str="Unsupported callback return type. Got: `{}`."):
122 import_numpy()
123 assert_cpu_sample_data_type(sample, error_str)
124 if isinstance(sample, np.ndarray):
125 return sample
126 if types._is_mxnet_array(sample):
127 if sample.context.device_type != "cpu":
128 raise TypeError(
129 "Unsupported callback return type. "
130 "GPU tensors are not supported. Got an MXNet GPU tensor."
131 )
132 return sample.asnumpy()
133 if types._is_torch_tensor(sample):
134 if sample.device.type != "cpu":
135 raise TypeError(
136 "Unsupported callback return type. "
137 "GPU tensors are not supported. Got a PyTorch GPU tensor."
138 )
139 return sample.numpy()
140 elif isinstance(sample, tensors.TensorCPU):
141 return np.array(sample)
142 raise TypeError(error_str.format(type(sample)))
143
144
145def batch_to_numpy(

Callers 5

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

Calls 3

import_numpyFunction · 0.70
typeFunction · 0.50

Tested by

no test coverage detected