Reverses the order of elements along the given spatial axis. Preserves shape. See `torch.flip` documentation for additional details: https://pytorch.org/docs/stable/generated/torch.flip.html This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resam
| 704 | |
| 705 | |
| 706 | class Flip(InvertibleTransform, LazyTransform): |
| 707 | """ |
| 708 | Reverses the order of elements along the given spatial axis. Preserves shape. |
| 709 | See `torch.flip` documentation for additional details: |
| 710 | https://pytorch.org/docs/stable/generated/torch.flip.html |
| 711 | |
| 712 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 713 | for more information. |
| 714 | |
| 715 | Args: |
| 716 | spatial_axis: spatial axes along which to flip over. Default is None. |
| 717 | The default `axis=None` will flip over all of the axes of the input array. |
| 718 | If axis is negative it counts from the last to the first axis. |
| 719 | If axis is a tuple of ints, flipping is performed on all of the axes |
| 720 | specified in the tuple. |
| 721 | lazy: a flag to indicate whether this transform should execute lazily or not. |
| 722 | Defaults to False |
| 723 | |
| 724 | """ |
| 725 | |
| 726 | backend = [TransformBackends.TORCH] |
| 727 | |
| 728 | def __init__(self, spatial_axis: Sequence[int] | int | None = None, lazy: bool = False) -> None: |
| 729 | LazyTransform.__init__(self, lazy=lazy) |
| 730 | self.spatial_axis = spatial_axis |
| 731 | |
| 732 | def __call__(self, img: torch.Tensor, lazy: bool | None = None) -> torch.Tensor: |
| 733 | """ |
| 734 | Args: |
| 735 | img: channel first array, must have shape: (num_channels, H[, W, ..., ]) |
| 736 | lazy: a flag to indicate whether this transform should execute lazily or not |
| 737 | during this call. Setting this to False or True overrides the ``lazy`` flag set |
| 738 | during initialization for this call. Defaults to None. |
| 739 | """ |
| 740 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 741 | lazy_ = self.lazy if lazy is None else lazy |
| 742 | return flip(img, self.spatial_axis, lazy=lazy_, transform_info=self.get_transform_info()) # type: ignore |
| 743 | |
| 744 | def inverse(self, data: torch.Tensor) -> torch.Tensor: |
| 745 | self.pop_transform(data) |
| 746 | flipper = Flip(spatial_axis=self.spatial_axis) |
| 747 | with flipper.trace_transform(False): |
| 748 | return flipper(data) |
| 749 | |
| 750 | |
| 751 | class Resize(InvertibleTransform, LazyTransform): |
no outgoing calls
searching dependent graphs…