MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ToNumpy

Class ToNumpy

monai/transforms/utility/array.py:501–523  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

499
500
501class 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
526class ToCupy(Transform):

Callers 10

inverseMethod · 0.90
__init__Method · 0.90
test_datasetMethod · 0.90
test_cupy_inputMethod · 0.90
test_numpy_inputMethod · 0.90
test_tensor_inputMethod · 0.90
test_list_tupleMethod · 0.90
test_single_valueMethod · 0.90

Calls

no outgoing calls

Tested by 7

test_datasetMethod · 0.72
test_cupy_inputMethod · 0.72
test_numpy_inputMethod · 0.72
test_tensor_inputMethod · 0.72
test_list_tupleMethod · 0.72
test_single_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…