Resize the input image to given spatial size (with scaling, not cropping/padding). Implemented using :py:class:`torch.nn.functional.interpolate`. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information. Args:
| 749 | |
| 750 | |
| 751 | class Resize(InvertibleTransform, LazyTransform): |
| 752 | """ |
| 753 | Resize the input image to given spatial size (with scaling, not cropping/padding). |
| 754 | Implemented using :py:class:`torch.nn.functional.interpolate`. |
| 755 | |
| 756 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 757 | for more information. |
| 758 | |
| 759 | Args: |
| 760 | spatial_size: expected shape of spatial dimensions after resize operation. |
| 761 | if some components of the `spatial_size` are non-positive values, the transform will use the |
| 762 | corresponding components of img size. For example, `spatial_size=(32, -1)` will be adapted |
| 763 | to `(32, 64)` if the second spatial dimension size of img is `64`. |
| 764 | size_mode: should be "all" or "longest", if "all", will use `spatial_size` for all the spatial dims, |
| 765 | if "longest", rescale the image so that only the longest side is equal to specified `spatial_size`, |
| 766 | which must be an int number in this case, keeping the aspect ratio of the initial image, refer to: |
| 767 | https://albumentations.ai/docs/api_reference/augmentations/geometric/resize/ |
| 768 | #albumentations.augmentations.geometric.resize.LongestMaxSize. |
| 769 | mode: {``"nearest"``, ``"nearest-exact"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``} |
| 770 | The interpolation mode. Defaults to ``"area"``. |
| 771 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html |
| 772 | align_corners: This only has an effect when mode is |
| 773 | 'linear', 'bilinear', 'bicubic' or 'trilinear'. Default: None. |
| 774 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html |
| 775 | anti_aliasing: bool |
| 776 | Whether to apply a Gaussian filter to smooth the image prior |
| 777 | to downsampling. It is crucial to filter when downsampling |
| 778 | the image to avoid aliasing artifacts. See also ``skimage.transform.resize`` |
| 779 | anti_aliasing_sigma: {float, tuple of floats}, optional |
| 780 | Standard deviation for Gaussian filtering used when anti-aliasing. |
| 781 | By default, this value is chosen as (s - 1) / 2 where s is the |
| 782 | downsampling factor, where s > 1. For the up-size case, s < 1, no |
| 783 | anti-aliasing is performed prior to rescaling. |
| 784 | dtype: data type for resampling computation. Defaults to ``float32``. |
| 785 | If None, use the data type of input data. |
| 786 | lazy: a flag to indicate whether this transform should execute lazily or not. |
| 787 | Defaults to False |
| 788 | """ |
| 789 | |
| 790 | backend = [TransformBackends.TORCH] |
| 791 | |
| 792 | def __init__( |
| 793 | self, |
| 794 | spatial_size: Sequence[int] | int, |
| 795 | size_mode: str = "all", |
| 796 | mode: str = InterpolateMode.AREA, |
| 797 | align_corners: bool | None = None, |
| 798 | anti_aliasing: bool = False, |
| 799 | anti_aliasing_sigma: Sequence[float] | float | None = None, |
| 800 | dtype: DtypeLike | torch.dtype = torch.float32, |
| 801 | lazy: bool = False, |
| 802 | ) -> None: |
| 803 | LazyTransform.__init__(self, lazy=lazy) |
| 804 | self.size_mode = look_up_option(size_mode, ["all", "longest"]) |
| 805 | self.spatial_size = spatial_size |
| 806 | self.mode = mode |
| 807 | self.align_corners = align_corners |
| 808 | self.anti_aliasing = anti_aliasing |
no outgoing calls
searching dependent graphs…