🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
[Enhance] Removed augmentation functional module. (#1067)
shijianjiane6fd826f67e4
diff --git a/docs/source/augmentation.module.rst b/docs/source/augmentation.module.rstindex c4357904a..2c4ce6af7 100644--- a/docs/source/augmentation.module.rst+++ b/docs/source/augmentation.module.rst@@ -33,9 +33,6 @@ Set of operators to perform data augmentation on 2D image tensors... autoclass:: RandomVerticalFlip.. autoclass:: RandomThinPlateSpline-.. automodule:: kornia.augmentation.functional.functional- :members:-.. currentmodule:: kornia.augmentation@@ -54,9 +51,6 @@ Set of operators to perform data augmentation on 3D volumetric tensors... autoclass:: RandomMotionBlur3D.. autoclass:: RandomEqualize3D-.. automodule:: kornia.augmentation.functional.functional3d- :members:-.. currentmodule:: kornia.augmentationdiff --git a/kornia/__init__.py b/kornia/__init__.pyindex a27d3b3da..d85320f44 100644--- a/kornia/__init__.py+++ b/kornia/__init__.py@@ -11,7 +11,6 @@ except ImportError:passfrom kornia import augmentation, color, contrib, enhance, feature, filters, geometry, jit, losses, morphology, utils-from kornia.augmentation.functional import *from kornia.color import (bgr_to_grayscale,bgr_to_rgb,@@ -95,3 +94,6 @@ from kornia.utils import ()# Exposes package functional to top level+++# Exposes package functional to top leveldiff --git a/kornia/augmentation/functional/__init__.py b/kornia/augmentation/functional/__init__.pydeleted file mode 100644index c996f9edf..000000000--- a/kornia/augmentation/functional/__init__.py+++ /dev/null@@ -1,2 +0,0 @@-from .functional import *-from .functional3d import *diff --git a/kornia/augmentation/functional/__temp__.py b/kornia/augmentation/functional/__temp__.pydeleted file mode 100644index 977c65d00..000000000--- a/kornia/augmentation/functional/__temp__.py+++ /dev/null@@ -1,23 +0,0 @@-import warnings-from functools import wraps-from typing import Callable---def __deprecation_warning(name: str, replacement: str):- warnings.warn(- f"`{name}` is no longer maintained and will be removed from the future versions. "- f"Please use {replacement} instead.",- category=DeprecationWarning,- )---def _deprecation_wrapper(f: Callable) -> Callable:- @wraps(f)- def wrapper(*args, **kwargs):- warnings.warn(- f"`{f.__name__}` is no longer maintained and will be removed from the future versions. ",- category=DeprecationWarning,- )- return f(*args, **kwargs)-- return wrapperdiff --git a/kornia/augmentation/functional/functional.py b/kornia/augmentation/functional/functional.pydeleted file mode 100644index 6e1d84804..000000000--- a/kornia/augmentation/functional/functional.py+++ /dev/null@@ -1,802 +0,0 @@-from typing import cast, Dict, Optional, Tuple--import torch--import kornia as K-from kornia.color import rgb_to_grayscale-from kornia.constants import BorderType, pi, Resample, SamplePadding-from kornia.enhance import (- adjust_brightness,- adjust_contrast,- adjust_gamma,- adjust_hue,- adjust_saturation,- equalize,- posterize,- sharpness,- solarize,-)-from kornia.filters import motion_blur-from kornia.geometry import (- bbox_generator,- bbox_to_mask,- crop_by_boxes,- deg2rad,- get_affine_matrix2d,- get_perspective_transform,- hflip,- infer_box_shape,- rotate,- vflip,- warp_affine,- warp_perspective,-)-from kornia.geometry.transform.affwarp import _compute_rotation_matrix, _compute_tensor_center--from ..utils import _shape_validation, _validate_input, _validate_input_shape-from .__temp__ import _deprecation_wrapper---@_deprecation_wrapper-@_validate_input-def apply_hflip(input: torch.Tensor) -> torch.Tensor:- r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters.-- Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: The horizontally flipped input with shape :math:`(*, C, H, W)`.- """-- return hflip(input)---@_deprecation_wrapper-@_validate_input-def compute_hflip_transformation(input: torch.Tensor) -> torch.Tensor:- r"""Compute the horizontal flip transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: The horizontal flip transformation matrix :math: `(*, 3, 3)`- """-- w: int = input.shape[-1]- flip_mat: torch.Tensor = torch.tensor(- [[-1, 0, w - 1], [0, 1, 0], [0, 0, 1]], device=input.device, dtype=input.dtype- )-- return flip_mat.repeat(input.size(0), 1, 1)---@_deprecation_wrapper-@_validate_input-def apply_vflip(input: torch.Tensor) -> torch.Tensor:- r"""Apply vertically flip on a tensor image or a batch of tensor images with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: Vertically flipped input with shape :math:`(B, C, H, W)`.- """-- return vflip(input)---@_deprecation_wrapper-@_validate_input-def compute_vflip_transformation(input: torch.Tensor) -> torch.Tensor:- r"""Compute the vertical flip transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: The vertical flip transformation matrix :math: `(*, 3, 3)`- """-- h: int = input.shape[-2]- flip_mat: torch.Tensor = torch.tensor(- [[1, 0, 0], [0, -1, h - 1], [0, 0, 1]], device=input.device, dtype=input.dtype- )-- return flip_mat.repeat(input.size(0), 1, 1)---@_deprecation_wrapper-@_validate_input-def apply_color_jitter(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Apply Color Jitter on a tensor image or a batch of tensor images with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['brightness_factor']: The brightness factor.- - params['contrast_factor']: The contrast factor.- - params['hue_factor']: The hue factor.- - params['saturation_factor']: The saturation factor.- - params['order']: The order of applying color transforms.- 0 is brightness, 1 is contrast, 2 is saturation, 4 is hue.-- Returns:- torch.Tensor: Color jitterred input with shape :math:`(B, C, H, W)`.- """-- transforms = [- lambda img: apply_adjust_brightness(img, params),- lambda img: apply_adjust_contrast(img, params),- lambda img: apply_adjust_saturation(img, params),- lambda img: apply_adjust_hue(img, params),- ]-- jittered = input- for idx in params['order'].tolist():- t = transforms[idx]- jittered = t(jittered)-- return jittered---@_deprecation_wrapper-@_validate_input-def compute_intensity_transformation(input: torch.Tensor):- r"""Compute the identity matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: The applied matrix :math: `(*, 3, 3)`.- """- identity: torch.Tensor = torch.eye(3, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)- return identity---@_deprecation_wrapper-@_validate_input-def apply_grayscale(input: torch.Tensor) -> torch.Tensor:- r"""Apply Gray Scale on a tensor image or a batch of tensor images with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: The grayscaled input with shape :math:`(B, C, H, W)`.- """- if not _validate_input_shape(input, 1, 3):- raise ValueError(f"Input size must have a shape of (*, 3, H, W). Got {input.shape}")-- grayscale: torch.Tensor = input.clone()-- # Make sure it returns (*, 3, H, W)- grayscale[:] = rgb_to_grayscale(input)-- return grayscale---@_deprecation_wrapper-@_validate_input-def apply_perspective(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Perform perspective transform of the given torch.Tensor or batch of tensors.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['start_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the original image with shape Bx4x2.- - params['end_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the transformed image with shape Bx4x2.- flags (Dict[str, torch.Tensor]):- - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: Perspectively transformed tensor.- """- _, _, height, width = input.shape-- # compute the homography between the input points- transform: torch.Tensor = compute_perspective_transformation(input, params)-- out_data: torch.Tensor = input.clone()-- # apply the computed transform- height, width = input.shape[-2:]- resample_name: str = Resample(flags['interpolation'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- out_data = warp_perspective(input, transform, (height, width), mode=resample_name, align_corners=align_corners)-- return out_data.view_as(input)---@_deprecation_wrapper-@_validate_input-def compute_perspective_transformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Compute the perspective transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['start_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the orignal image with shape Bx4x2.- - params['end_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the transformed image with shape Bx4x2.-- Returns:- torch.Tensor: The perspective transformation matrix :math: `(*, 3, 3)`- """- perspective_transform: torch.Tensor = get_perspective_transform(- params['start_points'], params['end_points']- ).type_as(input)-- transform: torch.Tensor = K.eye_like(3, input)-- transform = perspective_transform-- return transform---@_deprecation_wrapper-@_validate_input-def apply_affine(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Random affine transformation of the image keeping center invariant.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['angle']: Degrees of rotation.- - params['translations']: Horizontal and vertical translations.- - params['center']: Rotation center.- - params['scale']: Scaling params.- - params['sx']: Shear param toward x-axis.- - params['sy']: Shear param toward y-axis.- flags (Dict[str, torch.Tensor]):- - params['resample']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['padding_mode']: Integer tensor, see SamplePadding enum.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: The transfromed input with shape :math:`(B, C, H, W)`.- """- # arrange input data- x_data: torch.Tensor = input.view(-1, *input.shape[-3:])-- height, width = x_data.shape[-2:]-- # concatenate transforms- transform: torch.Tensor = compute_affine_transformation(input, params)-- resample_name: str = Resample(flags['resample'].item()).name.lower()- padding_mode: str = SamplePadding(flags['padding_mode'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- out_data: torch.Tensor = warp_affine(- x_data,- transform[:, :2, :],- (height, width),- resample_name,- align_corners=align_corners,- padding_mode=padding_mode,- )- return out_data.view_as(input)---@_deprecation_wrapper-@_validate_input-def compute_affine_transformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Compute the affine transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['angle']: Degrees of rotation.- - params['translations']: Horizontal and vertical translations.- - params['center']: Rotation center.- - params['scale']: Scaling params.- - params['sx']: Shear param toward x-axis.- - params['sy']: Shear param toward y-axis.-- Returns:- torch.Tensor: The affine transformation matrix :math: `(*, 3, 3)`.- """- transform = get_affine_matrix2d(- params['translations'],- params['center'],- params['scale'],- params['angle'],- deg2rad(params['sx']),- deg2rad(params['sy']),- ).type_as(input)- return transform---@_deprecation_wrapper-@_validate_input-def apply_rotation(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Rotate a tensor image or a batch of tensor images a random amount of degrees.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['degrees']: degree to be applied.- flags (Dict[str, torch.Tensor]):- - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: The cropped input.- """- angles: torch.Tensor = params["degrees"].type_as(input)-- resample_mode: str = Resample(flags['interpolation'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- transformed: torch.Tensor = rotate(input, angles, mode=resample_mode, align_corners=align_corners)-- return transformed---@_deprecation_wrapper-@_validate_input-def compute_rotate_tranformation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Compute the rotation transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['degrees']: degree to be applied.-- Returns:- torch.Tensor: The rotation transformation matrix :math: `(*, 3, 3)`- """- angles: torch.Tensor = params["degrees"].type_as(input)-- # TODO: This part should be inferred from rotate directly- center: torch.Tensor = _compute_tensor_center(input)- rotation_mat: torch.Tensor = _compute_rotation_matrix(angles, center.expand(angles.shape[0], -1))-- # rotation_mat is B x 2 x 3 and we need a B x 3 x 3 matrix- trans_mat: torch.Tensor = torch.eye(3, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)- trans_mat[:, 0] = rotation_mat[:, 0]- trans_mat[:, 1] = rotation_mat[:, 1]-- return trans_mat---@_deprecation_wrapper-@_validate_input-def apply_crop(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Apply cropping by src bounding box and dst bounding box.-- Order: top-left, top-right, bottom-right and bottom-left. The coordinates must be in the x, y order.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['src']: The applied cropping src matrix :math: `(*, 4, 2)`.- - params['dst']: The applied cropping dst matrix :math: `(*, 4, 2)`.- flags (Dict[str, torch.Tensor]):- - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: The cropped input.- """- resample_mode: str = Resample.get(flags['interpolation'].item()).name.lower() # type: ignore- align_corners: bool = cast(bool, flags['align_corners'].item())-- return crop_by_boxes(input, params['src'], params['dst'], resample_mode, align_corners=align_corners)---@_deprecation_wrapper-@_validate_input-def compute_crop_transformation(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]):- r"""Compute the applied transformation matrix :math: `(*, 3, 3)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['src']: The applied cropping src matrix :math: `(*, 4, 2)`.- - params['dst']: The applied cropping dst matrix :math: `(*, 4, 2)`.-- Returns:- torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)`- """- transform: torch.Tensor = get_perspective_transform(params['src'].to(input.dtype), params['dst'].to(input.dtype))- transform = transform.expand(input.shape[0], -1, -1).type_as(input)- return transform---@_deprecation_wrapper-@_validate_input-def apply_erase_rectangles(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Apply rectangle erase by params.-- Generate a {0, 1} mask with drawed rectangle having parameters defined by params and size by input.size().-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['widths']: widths tensor- - params['heights']: heights tensor- - params['xs']: x positions tensor- - params['ys']: y positions tensor- - params['values']: the value to fill in-- Returns:- torch.Tensor: Erased image with shape :math:`(B, C, H, W)`.- """- if not (params['widths'].size() == params['heights'].size() == params['xs'].size() == params['ys'].size()):- raise TypeError(- "rectangle params components must have same shape. "- f"Got ({params['widths'].size()}, {params['heights'].size()}) "- f"and ({params['xs'].size()}, {params['ys'].size()})"- )-- values = params['values'].unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).repeat(1, *input.shape[1:]).to(input)-- _, c, h, w = input.size()-- bboxes = bbox_generator(params['xs'], params['ys'], params['widths'], params['heights'])- mask = bbox_to_mask(bboxes, w, h) # Returns B, H, W- mask = mask.unsqueeze(1).repeat(1, c, 1, 1).to(input) # Transform to B, c, H, W- transformed = torch.where(mask == 1.0, values, input)- return transformed---@_deprecation_wrapper-@_validate_input-def apply_adjust_brightness(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- """Apply brightness adjustment.-- Wrapper for adjust_brightness for Torchvision-like param settings.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['brightness_factor']: Brightness adjust factor per element- in the batch. 0 gives a black image, 1 does not modify the input image and 2 gives a- white image, while any other number modify the brightness.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- transformed = adjust_brightness(input, params['brightness_factor'].to(input.dtype) - 1)-- return transformed---@_deprecation_wrapper-@_validate_input-def apply_adjust_contrast(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- """Apply contrast adjustment.-- Wrapper for adjust_contrast for Torchvision-like param settings.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['contrast_factor']: Contrast adjust factor per element in the batch.- 0 generates a compleatly black image, 1 does not modify the input image while any other- non-negative number modify the brightness by this factor.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- transformed = adjust_contrast(input, params['contrast_factor'].to(input.dtype))-- return transformed---@_deprecation_wrapper-@_validate_input-def apply_adjust_saturation(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- """Apply saturation adjustment.-- Wrapper for adjust_saturation for Torchvision-like param settings.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['saturation_factor']: How much to adjust the saturation. 0 will give a black- and white image, 1 will give the original image while 2 will enhance the saturation- by a factor of 2.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- transformed = adjust_saturation(input, params['saturation_factor'].to(input.dtype))-- return transformed---@_deprecation_wrapper-@_validate_input-def apply_adjust_hue(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- """Apply hue adjustment.-- Wrapper for adjust_hue for Torchvision-like param settings.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['hue_factor']: How much to shift the hue channel. Should be in [-0.5, 0.5].- 0.5 and -0.5 give complete reversal of hue channel in HSV space in positive and negative- direction respectively. 0 means no shift. Therefore, both -0.5 and 0.5 will give an- image with complementary colors while 0 gives the original image.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- transformed = adjust_hue(input, params['hue_factor'].to(input.dtype) * 2 * pi)-- return transformed---@_deprecation_wrapper-@_validate_input-def apply_adjust_gamma(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Perform gamma correction on an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['gamma_factor']: Non negative real number, same as γ\gammaγ in the equation.- gamma larger than 1 make the shadows darker, while gamma smaller than 1 make- dark regions lighter.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- transformed = adjust_gamma(input, params['gamma_factor'].to(input.dtype))-- return transformed---@_deprecation_wrapper-@_validate_input-def apply_motion_blur(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Perform motion blur on an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['ksize_factor']: motion kernel width and height (odd and positive).- - params['angle_factor']: angle of the motion blur in degrees (anti-clockwise rotation).- - params['direction_factor']: forward/backward direction of the motion blur.- Lower values towards -1.0 will point the motion blur towards the back (with- angle provided via angle), while higher values towards 1.0 will point the motion- blur forward. A value of 0.0 leads to a uniformly (but still angled) motion blur.- flags (Dict[str, torch.Tensor]):- - flags['border_type']: the padding mode to be applied before convolving.- CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.-- """- kernel_size: int = cast(int, params['ksize_factor'].unique().item())- angle = params['angle_factor']- direction = params['direction_factor']- border_type: str = cast(str, BorderType(flags['border_type'].item()).name.lower())- mode: str = cast(str, Resample(flags['interpolation'].item()).name.lower())-- return motion_blur(input, kernel_size, angle, direction, border_type, mode)---@_deprecation_wrapper-@_validate_input-def apply_solarize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Solarize an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['thresholds_factor']: thresholds ranged from 0 ~ 1.- - params['additions_factor']: additions to add on before solarizing.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- thresholds = params['thresholds_factor']- additions: Optional[torch.Tensor]- if 'additions_factor' in params:- additions = params['additions_factor']- else:- additions = None- return solarize(input, thresholds, additions)---@_deprecation_wrapper-@_validate_input-def apply_posterize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Posterize an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['bits_factor']: uint8 bits number ranged from 0 to 8.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- bits = params['bits_factor']-- return posterize(input, bits)---@_deprecation_wrapper-@_validate_input-def apply_sharpness(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Sharpen an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- params (Dict[str, torch.Tensor]):- - params['sharpness_factor']: Sharpness strength. Must be above 0.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- factor = params['sharpness_factor']-- return sharpness(input, factor)---@_deprecation_wrapper-@_validate_input-def apply_equalize(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Equalize an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.-- Returns:- torch.Tensor: Adjusted image with shape :math:`(B, C, H, W)`.- """- return equalize(input)---@_deprecation_wrapper-@_validate_input-def apply_mixup(- input: torch.Tensor, labels: torch.Tensor, params: Dict[str, torch.Tensor]-) -> Tuple[torch.Tensor, torch.Tensor]:- r"""Apply mixup to images in a batch.-- MixUp augmentation strategy: overlap images with different alpha values.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- labels (torch.Tensor): Label tensor with shape :math:`(B,)`.- params (Dict[str, torch.Tensor]):- - params['mixup_pairs']: Mixup indexes.- - params['mixup_lambdas']: Lambda for the mixup strength.-- Returns:- Tuple[torch.Tensor, torch.Tensor]:- - Adjusted image, shape of :math:`(B, C, H, W)`.- - Raw labels, corresponding labels and lambdas for each mix, shape of :math:`(B, 3)`.-- Examples:- >>> input = torch.stack([torch.eye(5).unsqueeze(dim=0), torch.ones(5, 5).unsqueeze(dim=0)])- >>> labels = torch.tensor([0, 1])- >>> params = dict(mixup_pairs=torch.tensor([1, 0]), mixup_lambdas=torch.tensor([0.5, 0.9]))- >>> out_img, out_label = apply_mixup(input, labels, params)- >>> out_img- tensor([[[[1.0000, 0.5000, 0.5000, 0.5000, 0.5000],- [0.5000, 1.0000, 0.5000, 0.5000, 0.5000],- [0.5000, 0.5000, 1.0000, 0.5000, 0.5000],- [0.5000, 0.5000, 0.5000, 1.0000, 0.5000],- [0.5000, 0.5000, 0.5000, 0.5000, 1.0000]]],- <BLANKLINE>- <BLANKLINE>- [[[1.0000, 0.1000, 0.1000, 0.1000, 0.1000],- [0.1000, 1.0000, 0.1000, 0.1000, 0.1000],- [0.1000, 0.1000, 1.0000, 0.1000, 0.1000],- [0.1000, 0.1000, 0.1000, 1.0000, 0.1000],- [0.1000, 0.1000, 0.1000, 0.1000, 1.0000]]]])- >>> out_label- tensor([[0.0000, 1.0000, 0.5000],- [1.0000, 0.0000, 0.9000]])- """- input_permute = input.index_select(dim=0, index=params['mixup_pairs'].to(input.device))- labels_permute = labels.index_select(dim=0, index=params['mixup_pairs'].to(labels.device))-- lam = params['mixup_lambdas'].view(-1, 1, 1, 1).expand_as(input).to(labels.device)- inputs = input * (1 - lam) + input_permute * lam- labels = torch.stack(- [- labels.to(input.dtype),- labels_permute.to(input.dtype),- params['mixup_lambdas'].to(labels.device, input.dtype),- ],- dim=-1,- ).to(labels.device)- return inputs, labels---@_deprecation_wrapper-@_validate_input-def apply_cutmix(- input: torch.Tensor, labels: torch.Tensor, params: Dict[str, torch.Tensor]-) -> Tuple[torch.Tensor, torch.Tensor]:- r"""Apply cutmix to images in a batch.-- CutMix augmentation strategy: patches are cut and pasted among training images where the ground- truth labels are also mixed proportionally to the area of the patches.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, H, W)`.- labels (torch.Tensor): Label tensor with shape :math:`(B,)`.- params (Dict[str, torch.Tensor]):- - params['mix_pairs']: Mixup indexes with shape :math:`(num_mixes, B)`.- - params['crop_src']: Lambda for the mixup strength :math:`(num_mixes, B, 4, 2)`.-- Returns:- Tuple[torch.Tensor, torch.Tensor]:- - Adjusted image, shape of :math:`(B, C, H, W)`.- - Corresponding labels and lambdas for each mix, shape of :math:`(num_mixes, B, 2)`.-- Examples:- >>> input = torch.stack([torch.zeros(1, 5, 5), torch.ones(1, 5, 5)], dim=0)- >>> labels = torch.tensor([0, 1])- >>> params = {'mix_pairs': torch.tensor([[1, 0]]), 'crop_src': torch.tensor([[[- ... [1., 1.],- ... [2., 1.],- ... [2., 2.],- ... [1., 2.]],- ... [[1., 1.],- ... [3., 1.],- ... [3., 2.],- ... [1., 2.]]]])}- >>> apply_cutmix(input, labels, params)- (tensor([[[[0., 0., 0., 0., 0.],- [0., 1., 1., 0., 0.],- [0., 1., 1., 0., 0.],- [0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0.]]],- <BLANKLINE>- <BLANKLINE>- [[[1., 1., 1., 1., 1.],- [1., 0., 0., 0., 1.],- [1., 0., 0., 0., 1.],- [1., 1., 1., 1., 1.],- [1., 1., 1., 1., 1.]]]]), tensor([[[0.0000, 1.0000, 0.1600],- [1.0000, 0.0000, 0.2400]]]))- """- height, width = input.size(2), input.size(3)- num_mixes = params['mix_pairs'].size(0)- batch_size = params['mix_pairs'].size(1)-- _shape_validation(params['mix_pairs'], [num_mixes, batch_size], 'mix_pairs')- _shape_validation(params['crop_src'], [num_mixes, batch_size, 4, 2], 'crop_src')-- out_inputs = input.clone()- out_labels = []- for pair, crop in zip(params['mix_pairs'], params['crop_src']):- input_permute = input.index_select(dim=0, index=pair.to(input.device))- labels_permute = labels.index_select(dim=0, index=pair.to(labels.device))- w, h = infer_box_shape(crop)- lam = w.to(input.dtype) * h.to(input.dtype) / (width * height) # width_beta * height_beta- # compute mask to match input shape- mask = bbox_to_mask(crop, width, height).bool().unsqueeze(dim=1).repeat(1, input.size(1), 1, 1)- out_inputs[mask] = input_permute[mask]- out_labels.append(- torch.stack([labels.to(input.dtype), labels_permute.to(input.dtype), lam.to(labels.device)], dim=1)- )-- return out_inputs, torch.stack(out_labels, dim=0)diff --git a/kornia/augmentation/functional/functional3d.py b/kornia/augmentation/functional/functional3d.pydeleted file mode 100644index fa0e7c5d1..000000000--- a/kornia/augmentation/functional/functional3d.py+++ /dev/null@@ -1,444 +0,0 @@-from typing import cast, Dict--import torch--import kornia as K-from kornia.constants import BorderType, Resample-from kornia.enhance import equalize3d-from kornia.filters import motion_blur3d-from kornia.geometry import (- crop_by_boxes3d,- deg2rad,- get_affine_matrix3d,- get_perspective_transform3d,- rotate3d,- warp_perspective3d,-)-from kornia.geometry.transform.affwarp import _compute_rotation_matrix3d, _compute_tensor_center3d-from kornia.geometry.transform.projwarp import warp_affine3d--from ..utils import _validate_input3d-from .__temp__ import _deprecation_wrapper---@_deprecation_wrapper-@_validate_input3d-def apply_hflip3d(input: torch.Tensor) -> torch.Tensor:- r"""Apply horizontal flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Horizontal flipped input with shape :math:`(*, C, D, H, W)`.- """-- return torch.flip(input, [-1])---@_deprecation_wrapper-@_validate_input3d-def compute_hflip_transformation3d(input: torch.Tensor) -> torch.Tensor:- r"""Compute the horizontal flip transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Horizontal flip transformation matrix :math: `(*, 4, 4)`.- """-- w: int = input.shape[-1]- flip_mat: torch.Tensor = torch.tensor([[-1, 0, 0, w - 1], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])-- return flip_mat.repeat(input.size(0), 1, 1).to(input)---@_deprecation_wrapper-@_validate_input3d-def apply_vflip3d(input: torch.Tensor) -> torch.Tensor:- r"""Apply vertical flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Vertical flipped input with shape :math:`(*, C, D, H, W)`.- """-- return torch.flip(input, [-2])---@_deprecation_wrapper-@_validate_input3d-def compute_vflip_transformation3d(input: torch.Tensor) -> torch.Tensor:- r"""Compute the veritical flip transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: The vertical flip transformation matrix :math: `(*, 4, 4)`.- """-- h: int = input.shape[-2]- flip_mat: torch.Tensor = torch.tensor([[1, 0, 0, 0], [0, -1, 0, h - 1], [0, 0, 1, 0], [0, 0, 0, 1]])-- return flip_mat.repeat(input.size(0), 1, 1).to(input)---@_deprecation_wrapper-@_validate_input3d-def apply_dflip3d(input: torch.Tensor) -> torch.Tensor:- r"""Apply depthical flip on a 3D tensor volume or a batch of tensors volumes with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Depthical flipped input with shape :math:`(*, C, D, H, W)`.- """-- return torch.flip(input, [-3])---@_deprecation_wrapper-@_validate_input3d-def compute_intensity_transformation3d(input: torch.Tensor):- r"""Compute the identity matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Identity matrix :math: `(*, 4, 4)`.- """- identity: torch.Tensor = torch.eye(4, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)- return identity---@_deprecation_wrapper-@_validate_input3d-def compute_dflip_transformation3d(input: torch.Tensor) -> torch.Tensor:- r"""Compute the depthical flip transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.-- Returns:- torch.Tensor: Depthical flip transformation matrix :math: `(*, 4, 4)`.- """-- d: int = input.shape[-3]- flip_mat: torch.Tensor = torch.tensor([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, d - 1], [0, 0, 0, 1]])-- return flip_mat.repeat(input.size(0), 1, 1).to(input)---@_deprecation_wrapper-@_validate_input3d-def apply_affine3d(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Random affine transformation of the image keeping center invariant.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['angles']: Degrees of rotation with the shape of :math: `(*, 3)` for yaw, pitch, roll.- - params['translations']: Horizontal, vertical and depthical translations (dx,dy,dz).- - params['center']: Rotation center (x,y,z).- - params['scale']: Isotropic scaling params.- - params['sxy']: Shear param toward x-y-axis.- - params['sxz']: Shear param toward x-z-axis.- - params['syx']: Shear param toward y-x-axis.- - params['syz']: Shear param toward y-z-axis.- - params['szx']: Shear param toward z-x-axis.- - params['szy']: Shear param toward z-y-axis.- flags (Dict[str, torch.Tensor]):- - params['resample']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: Affine transfromed input with shape :math:`(*, C, D, H, W)`.- """-- # arrange input data- x_data: torch.Tensor = input.view(-1, *input.shape[-4:])-- depth, height, width = x_data.shape[-3:]-- # concatenate transforms- transform: torch.Tensor = compute_affine_transformation3d(input, params)-- resample_name: str = Resample(flags['resample'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- out_data: torch.Tensor = warp_affine3d(- x_data, transform[:, :3, :], (depth, height, width), resample_name, align_corners=align_corners- )- return out_data.view_as(input)---@_deprecation_wrapper-@_validate_input3d-def compute_affine_transformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Compute the affine transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['angles']: Degrees of rotation with the shape of :math: `(*, 3)` for yaw, pitch, roll.- - params['translations']: Horizontal, vertical and depthical translations (dx,dy,dz).- - params['center']: Rotation center (x,y,z).- - params['scale']: Isotropic scaling params.- - params['sxy']: Shear param toward x-y-axis.- - params['sxz']: Shear param toward x-z-axis.- - params['syx']: Shear param toward y-x-axis.- - params['syz']: Shear param toward y-z-axis.- - params['szx']: Shear param toward z-x-axis.- - params['szy']: Shear param toward z-y-axis.-- Returns:- torch.Tensor: The affine transformation matrix :math: `(*, 4, 4)`.- """- transform = get_affine_matrix3d(- params['translations'],- params['center'],- params['scale'],- params['angles'],- deg2rad(params['sxy']),- deg2rad(params['sxz']),- deg2rad(params['syx']),- deg2rad(params['syz']),- deg2rad(params['szx']),- deg2rad(params['szy']),- ).to(input)- return transform---@_deprecation_wrapper-@_validate_input3d-def apply_rotation3d(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Rotate a tensor image or a batch of tensor images a random amount of degrees.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['degrees']: degree to be applied.- flags (Dict[str, torch.Tensor]):- - params['resample']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: The cropped input.- """- yaw: torch.Tensor = params["yaw"].to(input)- pitch: torch.Tensor = params["pitch"].to(input)- roll: torch.Tensor = params["roll"].to(input)-- resample_mode: str = Resample(flags['resample'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- transformed: torch.Tensor = rotate3d(input, yaw, pitch, roll, mode=resample_mode, align_corners=align_corners)-- return transformed---@_deprecation_wrapper-@_validate_input3d-def compute_rotate_tranformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]):- r"""Compute the rotation transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['yaw']: degree to be applied.- - params['pitch']: degree to be applied.- - params['roll']: degree to be applied.-- Returns:- torch.Tensor: The rotation transformation matrix :math: `(*, 4, 4)`.- """- yaw: torch.Tensor = params["yaw"].to(input)- pitch: torch.Tensor = params["pitch"].to(input)- roll: torch.Tensor = params["roll"].to(input)-- center: torch.Tensor = _compute_tensor_center3d(input)- rotation_mat: torch.Tensor = _compute_rotation_matrix3d(yaw, pitch, roll, center.expand(yaw.shape[0], -1))-- # rotation_mat is B x 3 x 4 and we need a B x 4 x 4 matrix- trans_mat: torch.Tensor = torch.eye(4, device=input.device, dtype=input.dtype).repeat(input.shape[0], 1, 1)- trans_mat[:, 0] = rotation_mat[:, 0]- trans_mat[:, 1] = rotation_mat[:, 1]- trans_mat[:, 2] = rotation_mat[:, 2]-- return trans_mat---@_deprecation_wrapper-@_validate_input3d-def apply_motion_blur3d(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Perform motion blur on an image.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['ksize_factor']: motion kernel width and height (odd and positive).- - params['angle_factor']: yaw, pitch and roll range of the motion blur in degrees :math:`(B, 3)`.- - params['direction_factor']: forward/backward direction of the motion blur.- Lower values towards -1.0 will point the motion blur towards the back (with- angle provided via angle), while higher values towards 1.0 will point the motion- blur forward. A value of 0.0 leads to a uniformly (but still angled) motion blur.- flags (Dict[str, torch.Tensor]):- - flags['border_type']: the padding mode to be applied before convolving.- CONSTANT = 0, REFLECT = 1, REPLICATE = 2, CIRCULAR = 3. Default: BorderType.CONSTANT.-- Returns:- torch.Tensor: adjusted image tensor with shape :math:`(*, C, D, H, W)`.- """-- kernel_size: int = cast(int, params['ksize_factor'].unique().item())- angle = params['angle_factor']- direction = params['direction_factor']- border_type: str = cast(str, BorderType(flags['border_type'].item()).name.lower())- mode: str = cast(str, Resample(flags['interpolation'].item()).name.lower())-- return motion_blur3d(input, kernel_size, angle, direction, border_type, mode)---@_deprecation_wrapper-@_validate_input3d-def apply_crop3d(input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Apply cropping by src bounding box and dst bounding box.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['src']: The applied cropping src matrix :math: `(*, 8, 3)`.- - params['dst']: The applied cropping dst matrix :math: `(*, 8, 3)`.- flags (Dict[str, torch.Tensor]):- - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: The cropped input.-- Note:- BBox order: front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,- back-top-right, back-bottom-right, back-bottom-left. The coordinates must be in x, y, z order.- """-- resample_mode: str = Resample.get(flags['interpolation'].item()).name.lower() # type: ignore- align_corners: bool = cast(bool, flags['align_corners'].item())-- return crop_by_boxes3d(input, params['src'], params['dst'], resample_mode, align_corners=align_corners)---@_deprecation_wrapper-@_validate_input3d-def compute_crop_transformation3d(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Compute the cropping transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['src']: The applied cropping src matrix :math: `(*, 8, 3)`.- - params['dst']: The applied cropping dst matrix :math: `(*, 8, 3)`.-- Returns:- torch.Tensor: The cropping transformation matrix :math: `(*, 4, 4)`.- """- transform: torch.Tensor = get_perspective_transform3d(params['src'].to(input.dtype), params['dst'].to(input.dtype))- transform = transform.expand(input.shape[0], -1, -1).to(input)- return transform---@_deprecation_wrapper-@_validate_input3d-def apply_perspective3d(- input: torch.Tensor, params: Dict[str, torch.Tensor], flags: Dict[str, torch.Tensor]-) -> torch.Tensor:- r"""Perform perspective transform of the given torch.Tensor or batch of tensors.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['start_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the original image with shape Bx8x3.- - params['end_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the transformed image with shape Bx8x3.- flags (Dict[str, torch.Tensor]):- - params['interpolation']: Integer tensor. NEAREST = 0, BILINEAR = 1.- - params['align_corners']: Boolean tensor.-- Returns:- torch.Tensor: Perspectively transformed tensor with shape :math:`(*, C, D, H, W)`.- """-- _, _, depth, height, width = input.shape-- # compute the homography between the input points- transform: torch.Tensor = compute_perspective_transformation3d(input, params)-- out_data: torch.Tensor = input.clone()-- # apply the computed transform- depth, height, width = input.shape[-3:]- resample_name: str = Resample(flags['interpolation'].item()).name.lower()- align_corners: bool = cast(bool, flags['align_corners'].item())-- out_data = warp_perspective3d(- input, transform, (depth, height, width), flags=resample_name, align_corners=align_corners- )-- return out_data.view_as(input)---@_deprecation_wrapper-@_validate_input3d-def compute_perspective_transformation3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Compute the perspective transformation matrix :math: `(*, 4, 4)`.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]):- - params['start_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the orignal image with shape Bx8x3.- - params['end_points']: Tensor containing [top-left, top-right, bottom-right,- bottom-left] of the transformed image with shape Bx8x3.-- Returns:- torch.Tensor: The perspective transformation matrix :math: `(*, 4, 4)`- """- perspective_transform: torch.Tensor = get_perspective_transform3d(params['start_points'], params['end_points']).to(- input- )-- transform: torch.Tensor = K.eye_like(4, input)-- transform = perspective_transform-- return transform---@_deprecation_wrapper-@_validate_input3d-def apply_equalize3d(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor:- r"""Equalize a tensor volume or a batch of tensors volumes with given random parameters.-- Args:- input (torch.Tensor): Tensor to be transformed with shape :math:`(*, C, D, H, W)`.- params (Dict[str, torch.Tensor]): shall be empty.-- Returns:- torch.Tensor: Equalized input with shape :math:`(*, C, D, H, W)`.- """-- return equalize3d(input)diff --git a/test/augmentation/test_functional.py b/test/augmentation/test_functional.pydeleted file mode 100644index b55326e8a..000000000--- a/test/augmentation/test_functional.py+++ /dev/null@@ -1,433 +0,0 @@-import torch-from torch.testing import assert_allclose--import kornia.augmentation.functional as F-from kornia.constants import pi---class TestHorizontalFlipFn:- def test_random_hflip(self, device, dtype):- input = torch.tensor(- [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 2.0]], device=device, dtype=dtype- ) # 3 x 4-- expected = torch.tensor(- [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [2.0, 1.0, 0.0, 0.0]], device=device, dtype=dtype- ) # 3 x 4-- assert (F.apply_hflip(input[None, None]) == expected).all()-- def test_batch_random_hflip(self, device, dtype):- batch_size = 5- input = torch.tensor(- [[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]]], device=device, dtype=dtype- ) # 1 x 1 x 3 x 3-- expected = torch.tensor(- [[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1.0, 1.0, 0.0]]]], device=device, dtype=dtype- ) # 1 x 1 x 3 x 3-- input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3- expected = expected.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3- assert (F.apply_hflip(input) == expected).all()---class TestVerticalFlipFn:- def test_random_vflip(self, device, dtype):- input = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]], device=device, dtype=dtype) # 3 x 3-- expected = torch.tensor(- [[0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], device=device, dtype=dtype- ) # 3 x 3-- assert (F.apply_vflip(input[None, None]) == expected).all()-- def test_batch_random_vflip(self, device, dtype):- batch_size = 5-- input = torch.tensor(- [[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]]], device=device, dtype=dtype- ) # 1 x 1 x 3 x 3-- expected = torch.tensor(- [[[[0.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]], device=device, dtype=dtype- ) # 1 x 1 x 3 x 3-- input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3- expected = expected.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3-- assert (F.apply_vflip(input) == expected).all()---class TestColorJitter:- def test_color_jitter(self):-- jitter_param = {- 'brightness_factor': torch.tensor(1.0),- 'contrast_factor': torch.tensor(1.0),- 'saturation_factor': torch.tensor(1.0),- 'hue_factor': torch.tensor(0.0),- 'order': torch.tensor([2, 3, 0, 1]),- }-- input = torch.rand(3, 5, 5) # 3 x 5 x 5-- expected = input-- assert_allclose(F.apply_color_jitter(input[None], jitter_param), expected[None], atol=1e-4, rtol=1e-5)-- def test_color_jitter_batch(self):- batch_size = 2- jitter_param = {- 'brightness_factor': torch.tensor([1.0] * batch_size),- 'contrast_factor': torch.tensor([1.0] * batch_size),- 'saturation_factor': torch.tensor([1.0] * batch_size),- 'hue_factor': torch.tensor([0.0] * batch_size),- 'order': torch.tensor([2, 3, 0, 1]),- }-- input = torch.rand(batch_size, 3, 5, 5) # 2 x 3 x 5 x 5- expected = input-- assert_allclose(F.apply_color_jitter(input, jitter_param), expected, atol=1e-4, rtol=1e-5)-- def test_random_brightness(self):- torch.manual_seed(42)- jitter_param = {- 'brightness_factor': torch.tensor([1.1529, 1.1660]),- 'contrast_factor': torch.tensor([1.0, 1.0]),- 'hue_factor': torch.tensor([0.0, 0.0]),- 'saturation_factor': torch.tensor([1.0, 1.0]),- 'order': torch.tensor([2, 3, 0, 1]),- }-- input = torch.tensor([[[[0.1, 0.2, 0.3], [0.6, 0.5, 0.4], [0.7, 0.8, 1.0]]]]) # 1 x 1 x 3 x 3- input = input.repeat(2, 3, 1, 1) # 2 x 3 x 3-- expected = torch.tensor(- [- [- [[0.2529, 0.3529, 0.4529], [0.7529, 0.6529, 0.5529], [0.8529, 0.9529, 1.0000]],- [[0.2529, 0.3529, 0.4529], [0.7529, 0.6529, 0.5529], [0.8529, 0.9529, 1.0000]],- [[0.2529, 0.3529, 0.4529], [0.7529, 0.6529, 0.5529], [0.8529, 0.9529, 1.0000]],- ],- [- [[0.2660, 0.3660, 0.4660], [0.7660, 0.6660, 0.5660], [0.8660, 0.9660, 1.0000]],- [[0.2660, 0.3660, 0.4660], [0.7660, 0.6660, 0.5660], [0.8660, 0.9660, 1.0000]],- [[0.2660, 0.3660, 0.4660], [0.7660, 0.6660, 0.5660], [0.8660, 0.9660, 1.0000]],- ],- ]- ) # 1 x 1 x 3 x 3-- assert_allclose(F.apply_color_jitter(input, jitter_param), expected)-- def test_random_contrast(self):- torch.manual_seed(42)- jitter_param = {- 'brightness_factor': torch.tensor([1.0, 1.0]),- 'contrast_factor': torch.tensor([0.9531, 1.1837]),- 'hue_factor': torch.tensor([0.0, 0.0]),- 'saturation_factor': torch.tensor([1.0, 1.0]),- 'order': torch.tensor([2, 3, 0, 1]),- }-- input = torch.tensor([[[[0.1, 0.2, 0.3], [0.6, 0.5, 0.4], [0.7, 0.8, 1.0]]]]) # 1 x 1 x 3 x 3- input = input.repeat(2, 3, 1, 1) # 2 x 3 x 3-- expected = torch.tensor(- [- [- [[0.0953, 0.1906, 0.2859], [0.5719, 0.4766, 0.3813], [0.6672, 0.7625, 0.9531]],- [[0.0953, 0.1906, 0.2859], [0.5719, 0.4766, 0.3813], [0.6672, 0.7625, 0.9531]],- [[0.0953, 0.1906, 0.2859], [0.5719, 0.4766, 0.3813], [0.6672, 0.7625, 0.9531]],- ],- [- [[0.1184, 0.2367, 0.3551], [0.7102, 0.5919, 0.4735], [0.8286, 0.9470, 1.0000]],- [[0.1184, 0.2367, 0.3551], [0.7102, 0.5919, 0.4735], [0.8286, 0.9470, 1.0000]],- [[0.1184, 0.2367, 0.3551], [0.7102, 0.5919, 0.4735], [0.8286, 0.9470, 1.0000]],- ],- ]- )-- assert_allclose(F.apply_color_jitter(input, jitter_param), expected, atol=1e-4, rtol=1e-5)-- def test_random_saturation(self):- torch.manual_seed(42)- jitter_param = {- 'brightness_factor': torch.tensor([1.0, 1.0]),- 'contrast_factor': torch.tensor([1.0, 1.0]),- 'hue_factor': torch.tensor([0.0, 0.0]),- 'saturation_factor': torch.tensor([0.9026, 1.1175]),- 'order': torch.tensor([2, 3, 0, 1]),- }-- input = torch.tensor(- [- [- [[0.1, 0.2, 0.3], [0.6, 0.5, 0.4], [0.7, 0.8, 1.0]],- [[1.0, 0.5, 0.6], [0.6, 0.3, 0.2], [0.8, 0.1, 0.2]],- [[0.6, 0.8, 0.7], [0.9, 0.3, 0.2], [0.8, 0.4, 0.5]],- ]- ]- ) # 1 x 1 x 3 x 3- input = input.repeat(2, 1, 1, 1) # 2 x 3 x 3-- expected = torch.tensor(- [- [- [- [1.8763e-01, 2.5842e-01, 3.3895e-01],- [6.2921e-01, 5.0000e-01, 4.0000e-01],- [7.0974e-01, 8.0000e-01, 1.0000e00],- ],- [- [1.0000e00, 5.2921e-01, 6.0974e-01],- [6.2921e-01, 3.1947e-01, 2.1947e-01],- [8.0000e-01, 1.6816e-01, 2.7790e-01],- ],- [- [6.3895e-01, 8.0000e-01, 7.0000e-01],- [9.0000e-01, 3.1947e-01, 2.1947e-01],- [8.0000e-01, 4.3895e-01, 5.4869e-01],- ],- ],- [- [- [1.1921e-07, 1.2953e-01, 2.5302e-01],- [5.6476e-01, 5.0000e-01, 4.0000e-01],- [6.8825e-01, 8.0000e-01, 1.0000e00],- ],- [- [1.0000e00, 4.6476e-01, 5.8825e-01],- [5.6476e-01, 2.7651e-01, 1.7651e-01],- [8.0000e-01, 1.7781e-02, 1.0603e-01],- ],- [- [5.5556e-01, 8.0000e-01, 7.0000e-01],- [9.0000e-01, 2.7651e-01, 1.7651e-01],- [8.0000e-01, 3.5302e-01, 4.4127e-01],- ],- ],- ]- )-- assert_allclose(F.apply_color_jitter(input, jitter_param), expected, atol=1e-4, rtol=1e-5)-- def test_random_hue(self):- torch.manual_seed(42)- jitter_param = {- 'brightness_factor': torch.tensor([1.0, 1.0]),- 'contrast_factor': torch.tensor([1.0, 1.0]),- 'hue_factor': torch.tensor([-0.0438 / 2 / pi, 0.0404 / 2 / pi]),- 'saturation_factor': torch.tensor([1.0, 1.0]),- 'order': torch.tensor([2, 3, 0, 1]),- }- input = torch.tensor(- [- [- [[0.1, 0.2, 0.3], [0.6, 0.5, 0.4], [0.7, 0.8, 1.0]],- [[1.0, 0.5, 0.6], [0.6, 0.3, 0.2], [0.8, 0.1, 0.2]],- [[0.6, 0.8, 0.7], [0.9, 0.3, 0.2], [0.8, 0.4, 0.5]],- ]- ]- ) # 1 x 1 x 3 x 3- input = input.repeat(2, 1, 1, 1) # 2 x 3 x 3-- expected = torch.tensor(- [- [- [[0.1000, 0.2000, 0.3000], [0.6000, 0.5000, 0.4000], [0.7000, 0.8000, 1.0000]],- [[1.0000, 0.5251, 0.6167], [0.6126, 0.3000, 0.2000], [0.8000, 0.1000, 0.2000]],- [[0.5623, 0.8000, 0.7000], [0.9000, 0.3084, 0.2084], [0.7958, 0.4293, 0.5335]],- ],- [- [[0.1000, 0.2000, 0.3000], [0.6116, 0.5000, 0.4000], [0.7000, 0.8000, 1.0000]],- [[1.0000, 0.4769, 0.5846], [0.6000, 0.3077, 0.2077], [0.7961, 0.1000, 0.2000]],- [[0.6347, 0.8000, 0.7000], [0.9000, 0.3000, 0.2000], [0.8000, 0.3730, 0.4692]],- ],- ]- )-- assert_allclose(F.apply_color_jitter(input, jitter_param), expected, atol=1e-4, rtol=1e-5)---class TestRandomGrayscale:- def test_opencv_true(self, device):- data = torch.tensor(- [- [- [0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],- [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],- [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],- [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],- [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593],- ],- [- [0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],- [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],- [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],- [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],- [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426],- ],- [- [0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],- [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],- [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],- [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],- [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532],- ],- ]- )- data = data.to(device)-- expected = torch.tensor(- [- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- ]- )- expected = expected.to(device)-- assert_allclose(F.apply_grayscale(data[None]), expected[None])-- def test_opencv_true_batch(self, device):- batch_size = 4- data = torch.tensor(- [- [- [0.3944633, 0.8597369, 0.1670904, 0.2825457, 0.0953912],- [0.1251704, 0.8020709, 0.8933256, 0.9170977, 0.1497008],- [0.2711633, 0.1111478, 0.0783281, 0.2771807, 0.5487481],- [0.0086008, 0.8288748, 0.9647092, 0.8922020, 0.7614344],- [0.2898048, 0.1282895, 0.7621747, 0.5657831, 0.9918593],- ],- [- [0.5414237, 0.9962701, 0.8947155, 0.5900949, 0.9483274],- [0.0468036, 0.3933847, 0.8046577, 0.3640994, 0.0632100],- [0.6171775, 0.8624780, 0.4126036, 0.7600935, 0.7279997],- [0.4237089, 0.5365476, 0.5591233, 0.1523191, 0.1382165],- [0.8932794, 0.8517839, 0.7152701, 0.8983801, 0.5905426],- ],- [- [0.2869580, 0.4700376, 0.2743714, 0.8135023, 0.2229074],- [0.9306560, 0.3734594, 0.4566821, 0.7599275, 0.7557513],- [0.7415742, 0.6115875, 0.3317572, 0.0379378, 0.1315770],- [0.8692724, 0.0809556, 0.7767404, 0.8742208, 0.1522012],- [0.7708948, 0.4509611, 0.0481175, 0.2358997, 0.6900532],- ],- ]- )- data = data.to(device)- data = data.unsqueeze(0).repeat(batch_size, 1, 1, 1)-- # Output data generated with OpenCV 4.1.1: cv2.cvtColor(img_np, cv2.COLOR_RGB2GRAY)- expected = torch.tensor(- [- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- [- [0.4684734, 0.8954562, 0.6064363, 0.5236061, 0.6106016],- [0.1709944, 0.5133104, 0.7915002, 0.5745703, 0.1680204],- [0.5279005, 0.6092287, 0.3034387, 0.5333768, 0.6064113],- [0.3503858, 0.5720159, 0.7052018, 0.4558409, 0.3261529],- [0.6988886, 0.5897652, 0.6532392, 0.7234108, 0.7218805],- ],- ]- )- expected = expected.to(device)- expected = expected.unsqueeze(0).repeat(batch_size, 1, 1, 1)-- assert_allclose(F.apply_grayscale(data), expected)---class TestRandomRectangleEarasing:- def test_rectangle_erasing1(self, device):- inputs = torch.ones(1, 1, 10, 10).to(device)- rect_params = {- "widths": torch.tensor([5]),- "heights": torch.tensor([5]),- "xs": torch.tensor([5]),- "ys": torch.tensor([5]),- "values": torch.tensor([0.0]),- }- expected = torch.tensor(- [- [- [- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],- [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],- ]- ]- ]- ).to(device)- assert_allclose(F.apply_erase_rectangles(inputs, rect_params), expected)-- def test_rectangle_erasing2(self, device):- inputs = torch.ones(3, 3, 3, 3).to(device)- rect_params = {- "widths": torch.tensor([3, 2, 1]),- "heights": torch.tensor([3, 2, 1]),- "xs": torch.tensor([0, 1, 2]),- "ys": torch.tensor([0, 1, 2]),- "values": torch.tensor([0.0, 0.0, 0.0]),- }- expected = torch.tensor(- [- [- [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],- [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],- [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],- ],- [- [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]],- [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]],- [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [1.0, 0.0, 0.0]],- ],- [- [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]],- [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]],- [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]],- ],- ]- ).to(device)-- assert_allclose(F.apply_erase_rectangles(inputs, rect_params), expected)diff --git a/test/augmentation/test_perspective.py b/test/augmentation/test_perspective.pyindex 607a6fe7b..475127e86 100644--- a/test/augmentation/test_perspective.py+++ b/test/augmentation/test_perspective.py@@ -4,38 +4,9 @@ from torch.autograd import gradcheckfrom torch.testing import assert_allcloseimport kornia-import kornia.augmentation.functional as Fimport kornia.testing as utils # test utils-class TestPerspective:- def test_smoke(self, device):- x_data = torch.rand(1, 2, 3, 4).to(device)- batch_prob = torch.rand(1, device=device) < 0.5- start_points = torch.rand(1, 4, 2).to(device)- end_points = torch.rand(1, 4, 2).to(device)-- params = dict(batch_prob=batch_prob, start_points=start_points, end_points=end_points)- flags = dict(interpolation=torch.tensor(1), align_corners=torch.tensor(False))- out_data = F.apply_perspective(x_data, params, flags)-- assert out_data.shape == x_data.shape-- def test_gradcheck(self, device):- input = torch.rand(1, 2, 3, 4).to(device)- input = utils.tensor_to_gradcheck_var(input) # to var-- start_points = torch.rand(1, 4, 2).to(device)- start_points = utils.tensor_to_gradcheck_var(start_points) # to var-- end_points = torch.rand(1, 4, 2).to(device)- end_points = utils.tensor_to_gradcheck_var(end_points) # to var-- params = dict(start_points=start_points, end_points=end_points)- flags = dict(interpolation=torch.tensor(1), align_corners=torch.tensor(False))- assert gradcheck(F.apply_perspective, (input, params, flags), raise_exception=True)--class TestRandomPerspective:torch.manual_seed(0) # for random reproductibilitydiff --git a/test/augmentation/test_transformation_matrix.py b/test/augmentation/test_transformation_matrix.pydeleted file mode 100644index d296dd099..000000000--- a/test/augmentation/test_transformation_matrix.py+++ /dev/null@@ -1,83 +0,0 @@-import torch-from torch.testing import assert_allclose--import kornia.augmentation.functional as F---class TestHorizontalFlipFn:- def test_random_hflip(self, device):- input = torch.tensor([[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 1.0, 2.0]]) # 3 x 4- input.to(device)-- expected_transform = torch.tensor([[-1.0, 0.0, 3.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]) # 3 x 3-- assert (F.compute_hflip_transformation(input[None, None]) == expected_transform).all()-- def test_batch_random_hflip(self, device):- batch_size = 5-- input = torch.tensor([[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]]]) # 1 x 1 x 3 x 3- input.to(device)-- expected_transform = torch.tensor([[[-1.0, 0.0, 2.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]]) # 1 x 3 x 3-- input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3- expected_transform = expected_transform.repeat(batch_size, 1, 1) # 5 x 3 x 3-- assert (F.compute_hflip_transformation(input) == expected_transform).all()---class TestVerticalFlipFn:- def test_random_vflip(self, device):-- input = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]) # 3 x 3- input.to(device)-- expected_transform = torch.tensor([[1.0, 0.0, 0.0], [0.0, -1.0, 2.0], [0.0, 0.0, 1.0]]) # 3 x 3-- assert (F.compute_vflip_transformation(input[None, None]) == expected_transform).all()-- def test_batch_random_vflip(self, device):- batch_size = 5-- input = torch.tensor([[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 1.0]]]]) # 1 x 1 x 3 x 3- input.to(device)-- expected_transform = torch.tensor([[[1.0, 0.0, 0.0], [0.0, -1.0, 2.0], [0.0, 0.0, 1.0]]]) # 1 x 3 x 3-- input = input.repeat(batch_size, 3, 1, 1) # 5 x 3 x 3 x 3- expected_transform = expected_transform.repeat(batch_size, 1, 1) # 5 x 3 x 3-- assert (F.compute_vflip_transformation(input) == expected_transform).all()---class TestIntensityTransformation:- def test_intensity_transformation(self):-- input = torch.rand(3, 5, 5) # 3 x 5 x 5-- expected_transform = torch.eye(3).unsqueeze(0) # 3 x 3-- assert_allclose(F.compute_intensity_transformation(input[None]), expected_transform, atol=1e-4, rtol=1e-5)-- def test_intensity_transformation_batch(self):- batch_size = 2-- input = torch.rand(batch_size, 3, 5, 5) # 2 x 3 x 5 x 5-- expected_transform = torch.eye(3).unsqueeze(0).expand((batch_size, 3, 3)) # 2 x 3 x 3-- assert_allclose(F.compute_intensity_transformation(input), expected_transform, atol=1e-4, rtol=1e-5)---class TestPerspective:- def test_smoke_transform(self, device):- x_data = torch.rand(1, 2, 3, 4).to(device)- batch_prob = torch.rand(1) < 0.5- start_points = torch.rand(1, 4, 2).to(device)- end_points = torch.rand(1, 4, 2).to(device)-- params = dict(batch_prob=batch_prob, start_points=start_points, end_points=end_points)- out_data = F.compute_perspective_transformation(x_data, params)-- assert out_data.shape == (1, 3, 3)