Grid distortion transform. Refer to: https://github.com/albumentations-team/albumentations/blob/master/albumentations/augmentations/transforms.py Args: num_cells: number of grid cells on each dimension. distort_steps: This argument is a list of tuple
(
self,
num_cells: tuple[int] | int,
distort_steps: Sequence[Sequence[float]],
mode: str | int = GridSampleMode.BILINEAR,
padding_mode: str = GridSamplePadMode.BORDER,
device: torch.device | None = None,
)
| 2991 | backend = [TransformBackends.TORCH] |
| 2992 | |
| 2993 | def __init__( |
| 2994 | self, |
| 2995 | num_cells: tuple[int] | int, |
| 2996 | distort_steps: Sequence[Sequence[float]], |
| 2997 | mode: str | int = GridSampleMode.BILINEAR, |
| 2998 | padding_mode: str = GridSamplePadMode.BORDER, |
| 2999 | device: torch.device | None = None, |
| 3000 | ) -> None: |
| 3001 | """ |
| 3002 | Grid distortion transform. Refer to: |
| 3003 | https://github.com/albumentations-team/albumentations/blob/master/albumentations/augmentations/transforms.py |
| 3004 | |
| 3005 | Args: |
| 3006 | num_cells: number of grid cells on each dimension. |
| 3007 | distort_steps: This argument is a list of tuples, where each tuple contains the distort steps of the |
| 3008 | corresponding dimensions (in the order of H, W[, D]). The length of each tuple equals to `num_cells + 1`. |
| 3009 | Each value in the tuple represents the distort step of the related cell. |
| 3010 | mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). |
| 3011 | Interpolation mode to calculate output values. Defaults to ``"bilinear"``. |
| 3012 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 3013 | When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used |
| 3014 | and the value represents the order of the spline interpolation. |
| 3015 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 3016 | padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``} |
| 3017 | Padding mode for outside grid values. Defaults to ``"border"``. |
| 3018 | See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html |
| 3019 | When `mode` is an integer, using numpy/cupy backends, this argument accepts |
| 3020 | {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}. |
| 3021 | See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html |
| 3022 | device: device on which the tensor will be allocated. |
| 3023 | |
| 3024 | """ |
| 3025 | self.resampler = Resample(mode=mode, padding_mode=padding_mode, device=device) |
| 3026 | self.num_cells = num_cells |
| 3027 | self.distort_steps = distort_steps |
| 3028 | self.device = device |
| 3029 | |
| 3030 | def __call__( |
| 3031 | self, |