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

Class PipelineBatchAdapter

dali/python/nvidia/dali/_tensor_formatting.py:156–178  ·  view source on GitHub ↗

Adapter for TensorListCPU/TensorListGPU. Implements BatchAdapter protocol.

Source from the content-addressed store, hash-verified

154
155
156class PipelineBatchAdapter(_BasePipelineAdapter):
157 """Adapter for TensorListCPU/TensorListGPU. Implements BatchAdapter protocol."""
158
159 def get_length(self, obj) -> int:
160 return len(obj)
161
162 def get_sample(self, obj, index: int):
163 return obj[index]
164
165 def to_numpy(self, obj, edgeitems=None):
166 cpu_obj = self.to_cpu(obj)
167 length = len(cpu_obj)
168
169 if length == 0:
170 return []
171
172 # Check if we should crop
173 if edgeitems is not None and length > 2 * edgeitems + 1:
174 # Only convert edge samples
175 indices = list(range(edgeitems)) + list(range(length - edgeitems, length))
176 return [np.array(cpu_obj[i]) for i in indices]
177
178 return [np.array(cpu_obj[i]) for i in range(length)]
179
180
181# Dynamic API adapters (ndd.Tensor, ndd.Batch)

Callers 2

_tensorlist_to_stringFunction · 0.90
format_batchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected