Adapter for TensorListCPU/TensorListGPU. Implements BatchAdapter protocol.
| 154 | |
| 155 | |
| 156 | class 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) |
no outgoing calls
no test coverage detected