Converts the input data to CuPy array, can support list or tuple of numbers, NumPy and PyTorch Tensor. Args: dtype: data type specifier. It is inferred from the input by default. if not None, must be an argument of `numpy.dtype`, for more details: https://do
| 524 | |
| 525 | |
| 526 | class ToCupy(Transform): |
| 527 | """ |
| 528 | Converts the input data to CuPy array, can support list or tuple of numbers, NumPy and PyTorch Tensor. |
| 529 | |
| 530 | Args: |
| 531 | dtype: data type specifier. It is inferred from the input by default. |
| 532 | if not None, must be an argument of `numpy.dtype`, for more details: |
| 533 | https://docs.cupy.dev/en/stable/reference/generated/cupy.array.html. |
| 534 | wrap_sequence: if `False`, then lists will recursively call this function, default to `True`. |
| 535 | E.g., if `False`, `[1, 2]` -> `[array(1), array(2)]`, if `True`, then `[1, 2]` -> `array([1, 2])`. |
| 536 | |
| 537 | """ |
| 538 | |
| 539 | backend = [TransformBackends.CUPY] |
| 540 | |
| 541 | def __init__(self, dtype: np.dtype | None = None, wrap_sequence: bool = True) -> None: |
| 542 | super().__init__() |
| 543 | self.dtype = dtype |
| 544 | self.wrap_sequence = wrap_sequence |
| 545 | |
| 546 | def __call__(self, data: NdarrayOrTensor): |
| 547 | """ |
| 548 | Create a CuPy array from `data` and make it contiguous |
| 549 | """ |
| 550 | return convert_to_cupy(data, dtype=self.dtype, wrap_sequence=self.wrap_sequence) |
| 551 | |
| 552 | |
| 553 | class ToPIL(Transform): |
no outgoing calls
searching dependent graphs…