Converts the input data to numpy array, can support list or tuple of numbers and PyTorch Tensor. Args: dtype: target data type when converting to numpy array. wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. E.g., if
| 499 | |
| 500 | |
| 501 | class ToNumpy(Transform): |
| 502 | """ |
| 503 | Converts the input data to numpy array, can support list or tuple of numbers and PyTorch Tensor. |
| 504 | |
| 505 | Args: |
| 506 | dtype: target data type when converting to numpy array. |
| 507 | wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. |
| 508 | E.g., if `False`, `[1, 2]` -> `[array(1), array(2)]`, if `True`, then `[1, 2]` -> `array([1, 2])`. |
| 509 | |
| 510 | """ |
| 511 | |
| 512 | backend = [TransformBackends.NUMPY] |
| 513 | |
| 514 | def __init__(self, dtype: DtypeLike = None, wrap_sequence: bool = True) -> None: |
| 515 | super().__init__() |
| 516 | self.dtype = dtype |
| 517 | self.wrap_sequence = wrap_sequence |
| 518 | |
| 519 | def __call__(self, img: NdarrayOrTensor): |
| 520 | """ |
| 521 | Apply the transform to `img` and make it contiguous. |
| 522 | """ |
| 523 | return convert_to_numpy(img, dtype=self.dtype, wrap_sequence=self.wrap_sequence) |
| 524 | |
| 525 | |
| 526 | class ToCupy(Transform): |
no outgoing calls
searching dependent graphs…