2727from monai .data .meta_tensor import MetaObj , MetaTensor
2828from monai .data .utils import no_collation
2929from monai .transforms .inverse import InvertibleTransform
30- from monai .transforms .transform import MapTransform , Randomizable , RandomizableTransform
30+ from monai .transforms .transform import MapTransform , Randomizable , RandomizableTrait , RandomizableTransform
3131from monai .transforms .utility .array import (
3232 AddChannel ,
3333 AddCoordinateChannels ,
@@ -1457,51 +1457,38 @@ def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> Dict[Hashable, N
14571457 return d
14581458
14591459
1460- class RandTorchVisiond (RandomizableTransform , MapTransform ):
1460+ class RandTorchVisiond (MapTransform , RandomizableTrait ):
14611461 """
14621462 Dictionary-based wrapper of :py:class:`monai.transforms.TorchVision` for randomized transforms.
14631463 For deterministic non-randomized transforms of TorchVision use :py:class:`monai.transforms.TorchVisiond`.
14641464
1465+ Args:
1466+ keys: keys of the corresponding items to be transformed.
1467+ See also: :py:class:`monai.transforms.compose.MapTransform`
1468+ name: The transform name in TorchVision package.
1469+ allow_missing_keys: don't raise exception if key is missing.
1470+ args: parameters for the TorchVision transform.
1471+ kwargs: parameters for the TorchVision transform.
1472+
14651473 Note:
14661474
14671475 - As most of the TorchVision transforms only work for PIL image and PyTorch Tensor, this transform expects input
1468- data to be dict of PyTorch Tensors, users can easily call `ToTensord` transform to convert Numpy to Tensor.
1469- - This class inherits the ``RandomizableTransform `` purely to prevent any dataset caching to skip the transform
1476+ data to be dict of PyTorch Tensors. Users should call `ToTensord` transform first to convert Numpy to Tensor.
1477+ - This class inherits the ``Randomizable `` purely to prevent any dataset caching to skip the transform
14701478 computation. If the random factor of the underlying torchvision transform is not derived from `self.R`,
1471- the results may not be deterministic. It also provides the probability to apply this transform.
1472- See Also: :py:class:`monai.transforms.RandomizableTransform`.
1479+ the results may not be deterministic. See Also: :py:class:`monai.transforms.Randomizable`.
14731480
14741481 """
14751482
14761483 backend = TorchVision .backend
14771484
1478- def __init__ (
1479- self , keys : KeysCollection , name : str , prob : float = 1.0 , allow_missing_keys : bool = False , * args , ** kwargs
1480- ) -> None :
1481- """
1482- Args:
1483- keys: keys of the corresponding items to be transformed.
1484- See also: :py:class:`monai.transforms.compose.MapTransform`
1485- name: The transform name in TorchVision package.
1486- prob: Probability of applying this transform.
1487- allow_missing_keys: don't raise exception if key is missing.
1488- args: parameters for the TorchVision transform.
1489- kwargs: parameters for the TorchVision transform.
1490-
1491- """
1492- RandomizableTransform .__init__ (self , prob = prob )
1485+ def __init__ (self , keys : KeysCollection , name : str , allow_missing_keys : bool = False , * args , ** kwargs ) -> None :
14931486 MapTransform .__init__ (self , keys , allow_missing_keys )
1494-
14951487 self .name = name
14961488 self .trans = TorchVision (name , * args , ** kwargs )
14971489
14981490 def __call__ (self , data : Mapping [Hashable , NdarrayOrTensor ]) -> Dict [Hashable , NdarrayOrTensor ]:
14991491 d = dict (data )
1500-
1501- self .randomize (data )
1502- if not self ._do_transform :
1503- return d
1504-
15051492 for key in self .key_iterator (d ):
15061493 d [key ] = self .trans (d [key ])
15071494 return d
@@ -1677,7 +1664,7 @@ def __call__(self, data):
16771664 return d
16781665
16791666
1680- class RandCuCIMd (CuCIMd , RandomizableTransform ):
1667+ class RandCuCIMd (MapTransform , RandomizableTrait ):
16811668 """
16821669 Dictionary-based wrapper of :py:class:`monai.transforms.CuCIM` for randomized transforms.
16831670 For deterministic non-randomized transforms of CuCIM use :py:class:`monai.transforms.CuCIMd`.
@@ -1686,25 +1673,22 @@ class RandCuCIMd(CuCIMd, RandomizableTransform):
16861673 keys: keys of the corresponding items to be transformed.
16871674 See also: :py:class:`monai.transforms.compose.MapTransform`
16881675 name: The transform name in CuCIM package.
1689- apply_prob: the probability to apply the transform (default=1.0)
16901676 allow_missing_keys: don't raise exception if key is missing.
16911677 args: parameters for the CuCIM transform.
16921678 kwargs: parameters for the CuCIM transform.
16931679
16941680 Note:
16951681 - CuCIM transform only work with CuPy arrays, so this transform expects input data to be `cupy.ndarray`.
1696- Users can call `ToCuPy` transform to convert a numpy array or torch tensor to cupy array.
1697- - If the cuCIM transform is already randomized the `apply_prob` argument has nothing to do with
1698- the randomness of the underlying cuCIM transform. `apply_prob` defines if the transform (either randomized
1699- or non-randomized) being applied randomly, so it can apply non-randomized transforms randomly but be careful
1700- with setting `apply_prob` to anything than 1.0 when using along with cuCIM's randomized transforms.
1701- - If the random factor of the underlying cuCIM transform is not derived from `self.R`,
1682+ Users should call `ToCuPy` transform first to convert a numpy array or torch tensor to cupy array.
1683+ - This class inherits the ``Randomizable`` purely to prevent any dataset caching to skip the transform
1684+ computation. If the random factor of the underlying cuCIM transform is not derived from `self.R`,
17021685 the results may not be deterministic. See Also: :py:class:`monai.transforms.Randomizable`.
17031686 """
17041687
1705- def __init__ (self , apply_prob : float = 1.0 , * args , ** kwargs ) -> None :
1706- CuCIMd .__init__ (self , * args , ** kwargs )
1707- RandomizableTransform .__init__ (self , prob = apply_prob )
1688+ def __init__ (self , keys : KeysCollection , name : str , allow_missing_keys : bool = False , * args , ** kwargs ) -> None :
1689+ MapTransform .__init__ (self , keys , allow_missing_keys )
1690+ self .name = name
1691+ self .trans = CuCIM (name , * args , ** kwargs )
17081692
17091693 def __call__ (self , data ):
17101694 """
@@ -1715,10 +1699,10 @@ def __call__(self, data):
17151699 Dict[Hashable, `cupy.ndarray`]
17161700
17171701 """
1718- self . randomize (data )
1719- if not self ._do_transform :
1720- return dict ( data )
1721- return super (). __call__ ( data )
1702+ d = dict (data )
1703+ for key in self .key_iterator ( d ) :
1704+ d [ key ] = self . trans ( d [ key ] )
1705+ return d
17221706
17231707
17241708class AddCoordinateChannelsd (MapTransform ):
0 commit comments