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

Class RandAxisFlipd

monai/transforms/spatial/dictionary.py:1644–1721  ·  view source on GitHub ↗

Dictionary-based version :py:class:`monai.transforms.RandAxisFlip`. See `numpy.flip` for additional details. https://docs.scipy.org/doc/numpy/reference/generated/numpy.flip.html This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic `

Source from the content-addressed store, hash-verified

1642
1643
1644class RandAxisFlipd(RandomizableTransform, MapTransform, InvertibleTransform, LazyTransform):
1645 """
1646 Dictionary-based version :py:class:`monai.transforms.RandAxisFlip`.
1647
1648 See `numpy.flip` for additional details.
1649 https://docs.scipy.org/doc/numpy/reference/generated/numpy.flip.html
1650
1651 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
1652 for more information.
1653
1654 Args:
1655 keys: Keys to pick data for transformation.
1656 prob: Probability of flipping.
1657 allow_missing_keys: don&#x27;t raise exception if key is missing.
1658 lazy: a flag to indicate whether this transform should execute lazily or not.
1659 Defaults to False
1660 """
1661
1662 backend = RandAxisFlip.backend
1663
1664 def __init__(
1665 self, keys: KeysCollection, prob: float = 0.1, allow_missing_keys: bool = False, lazy: bool = False
1666 ) -> None:
1667 MapTransform.__init__(self, keys, allow_missing_keys)
1668 RandomizableTransform.__init__(self, prob)
1669 LazyTransform.__init__(self, lazy=lazy)
1670 self.flipper = RandAxisFlip(prob=1.0, lazy=lazy)
1671
1672 @LazyTransform.lazy.setter # type: ignore
1673 def lazy(self, val: bool):
1674 self.flipper.lazy = val
1675 self._lazy = val
1676
1677 def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandAxisFlipd:
1678 super().set_random_state(seed, state)
1679 self.flipper.set_random_state(seed, state)
1680 return self
1681
1682 def __call__(self, data: Mapping[Hashable, torch.Tensor], lazy: bool | None = None) -> dict[Hashable, torch.Tensor]:
1683 """
1684 Args:
1685 data: a dictionary containing the tensor-like data to be processed. The ``keys`` specified
1686 in this dictionary must be tensor like arrays that are channel first and have at most
1687 three spatial dimensions
1688 lazy: a flag to indicate whether this transform should execute lazily or not
1689 during this call. Setting this to False or True overrides the ``lazy`` flag set
1690 during initialization for this call. Defaults to None.
1691
1692 Returns:
1693 a dictionary containing the transformed data, as well as any other data present in the dictionary
1694 """
1695 d = dict(data)
1696 first_key: Hashable = self.first_key(d)
1697 if first_key == ():
1698 return d
1699
1700 self.randomize(None)
1701

Callers 5

test_train_timingMethod · 0.90
test_correct_resultsMethod · 0.90
test_inverse.pyFile · 0.90
test_invertMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_train_timingMethod · 0.72
test_correct_resultsMethod · 0.72
test_invertMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…