diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bee9d11bb..e6ebf8c28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,10 @@ name: CI on: push: branches: - - master + - main pull_request: + branches: + - main jobs: test_and_lint: @@ -40,7 +42,6 @@ jobs: - name: Install dependencies run: | pip install .[tests] - pip install imgaug - name: Cleanup the build directory uses: JesseTG/rm@v1.0.3 with: diff --git a/README.md b/README.md index 288148da0..c01f42b24 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ Pixel-level transforms will change just an input image and will leave any additi - [ZoomBlur](https://albumentations.ai/docs/api_reference/augmentations/blur/transforms/#albumentations.augmentations.blur.transforms.ZoomBlur) ### Spatial-level transforms + Spatial-level transforms will simultaneously change both an input image as well as additional targets such as masks, bounding boxes, and keypoints. The following table shows which additional targets are supported by each transform. | Transform | Image | Masks | BBoxes | Keypoints | @@ -237,21 +238,26 @@ Spatial-level transforms will simultaneously change both an input image as well | [VerticalFlip](https://albumentations.ai/docs/api_reference/augmentations/geometric/transforms/#albumentations.augmentations.geometric.transforms.VerticalFlip) | ✓ | ✓ | ✓ | ✓ | ## A few more examples of augmentations + ### Semantic segmentation on the Inria dataset ![inria](https://habrastorage.org/webt/su/wa/np/suwanpeo6ww7wpwtobtrzd_cg20.jpeg) ### Medical imaging + ![medical](https://habrastorage.org/webt/1i/fi/wz/1ifiwzy0lxetc4nwjvss-71nkw0.jpeg) ### Object detection and semantic segmentation on the Mapillary Vistas dataset + ![vistas](https://habrastorage.org/webt/rz/-h/3j/rz-h3jalbxic8o_fhucxysts4tc.jpeg) ### Keypoints augmentation + ## Benchmarking results + To run the benchmark yourself, follow the instructions in [benchmark/README.md](https://github.com/albumentations-team/albumentations/blob/master/benchmark/README.md) Results for running the benchmark on the first 2000 images from the ImageNet validation set using an Intel(R) Xeon(R) Gold 6140 CPU. diff --git a/albumentations/__init__.py b/albumentations/__init__.py index 760626a07..32bcdf5f4 100644 --- a/albumentations/__init__.py +++ b/albumentations/__init__.py @@ -4,10 +4,3 @@ from .core.composition import * from .core.serialization import * from .core.transforms_interface import * - -try: - from .imgaug.transforms import * # type: ignore -except ImportError: - # imgaug is not installed by default, so we import stubs. - # Run `pip install -U albumentations[imgaug] if you need augmentations from imgaug.` - from .imgaug.stubs import * # type: ignore diff --git a/albumentations/augmentations/__init__.py b/albumentations/augmentations/__init__.py index 79da4b649..de00b12b8 100644 --- a/albumentations/augmentations/__init__.py +++ b/albumentations/augmentations/__init__.py @@ -8,7 +8,6 @@ from .domain_adaptation import * from .dropout.channel_dropout import * from .dropout.coarse_dropout import * -from .dropout.cutout import * from .dropout.functional import * from .dropout.grid_dropout import * from .dropout.mask_dropout import * diff --git a/albumentations/augmentations/dropout/__init__.py b/albumentations/augmentations/dropout/__init__.py index aa29f452a..1a2eb9463 100644 --- a/albumentations/augmentations/dropout/__init__.py +++ b/albumentations/augmentations/dropout/__init__.py @@ -1,5 +1,4 @@ from .channel_dropout import * from .coarse_dropout import * -from .cutout import * from .grid_dropout import * from .mask_dropout import * diff --git a/albumentations/augmentations/dropout/cutout.py b/albumentations/augmentations/dropout/cutout.py deleted file mode 100644 index 332b8b8f7..000000000 --- a/albumentations/augmentations/dropout/cutout.py +++ /dev/null @@ -1,85 +0,0 @@ -import random -import warnings -from typing import Any, Dict, Iterable, List, Tuple, Union - -import numpy as np - -from albumentations.core.transforms_interface import ImageOnlyTransform - -from .functional import cutout - -__all__ = ["Cutout"] - - -class Cutout(ImageOnlyTransform): - """CoarseDropout of the square regions in the image. - - Args: - num_holes (int): number of regions to zero out - max_h_size (int): maximum height of the hole - max_w_size (int): maximum width of the hole - fill_value (int, float, list of int, list of float): value for dropped pixels. - - Targets: - image - - Image types: - uint8, float32 - - Reference: - | https://arxiv.org/abs/1708.04552 - | https://github.com/uoguelph-mlrg/Cutout/blob/master/util/cutout.py - | https://github.com/aleju/imgaug/blob/master/imgaug/augmenters/arithmetic.py - """ - - def __init__( - self, - num_holes: int = 8, - max_h_size: int = 8, - max_w_size: int = 8, - fill_value: Union[int, float] = 0, - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.num_holes = num_holes - self.max_h_size = max_h_size - self.max_w_size = max_w_size - self.fill_value = fill_value - warnings.warn( - f"{self.__class__.__name__} has been deprecated. Please use CoarseDropout", - FutureWarning, - ) - - def apply( - self, - img: np.ndarray, - fill_value: Union[int, float] = 0, - holes: Iterable[Tuple[int, int, int, int]] = (), - **params: Any, - ) -> np.ndarray: - return cutout(img, holes, fill_value) - - def get_params_dependent_on_targets(self, params: Dict[str, Any]) -> Dict[str, Any]: - img = params["image"] - height, width = img.shape[:2] - - holes = [] - for _n in range(self.num_holes): - y = random.randint(0, height) - x = random.randint(0, width) - - y1 = np.clip(y - self.max_h_size // 2, 0, height) - y2 = np.clip(y1 + self.max_h_size, 0, height) - x1 = np.clip(x - self.max_w_size // 2, 0, width) - x2 = np.clip(x1 + self.max_w_size, 0, width) - holes.append((x1, y1, x2, y2)) - - return {"holes": holes} - - @property - def targets_as_params(self) -> List[str]: - return ["image"] - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return "num_holes", "max_h_size", "max_w_size" diff --git a/albumentations/augmentations/dropout/functional.py b/albumentations/augmentations/dropout/functional.py index b93a3f91a..d3f17752e 100644 --- a/albumentations/augmentations/dropout/functional.py +++ b/albumentations/augmentations/dropout/functional.py @@ -1,10 +1,10 @@ -from typing import Iterable, List, Tuple, Union +from typing import Iterable, Tuple, Union import numpy as np from albumentations.augmentations.utils import preserve_shape -__all__ = ["cutout", "channel_dropout"] +__all__ = ["channel_dropout"] @preserve_shape diff --git a/albumentations/augmentations/transforms.py b/albumentations/augmentations/transforms.py index b649f8fec..32d9fd655 100644 --- a/albumentations/augmentations/transforms.py +++ b/albumentations/augmentations/transforms.py @@ -42,8 +42,6 @@ "RandomGridShuffle", "HueSaturationValue", "RGBShift", - "RandomBrightness", - "RandomContrast", "GaussNoise", "CLAHE", "ChannelShuffle", @@ -51,7 +49,6 @@ "ToGray", "ToRGB", "ToSepia", - "JpegCompression", "ImageCompression", "ToFloat", "FromFloat", @@ -294,40 +291,6 @@ def get_transform_init_args(self) -> Dict[str, Any]: } -class JpegCompression(ImageCompression): - """Decreases image quality by Jpeg compression of an image. - - Args: - quality_lower: lower bound on the jpeg quality. Should be in [0, 100] range - quality_upper: upper bound on the jpeg quality. Should be in [0, 100] range - - Targets: - image - - Image types: - uint8, float32 - """ - - def __init__(self, quality_lower: int = 99, quality_upper: int = 100, always_apply: bool = False, p: float = 0.5): - super().__init__( - quality_lower=quality_lower, - quality_upper=quality_upper, - compression_type=ImageCompression.ImageCompressionType.JPEG, - always_apply=always_apply, - p=p, - ) - warnings.warn( - f"{self.__class__.__name__} has been deprecated. Please use ImageCompression", - FutureWarning, - ) - - def get_transform_init_args(self) -> Dict[str, float]: - return { - "quality_lower": self.quality_lower, - "quality_upper": self.quality_upper, - } - - class RandomSnow(ImageOnlyTransform): """Bleach out some pixel values simulating snow. @@ -1266,58 +1229,6 @@ def get_transform_init_args_names(self) -> Tuple[str, str, str]: return ("brightness_limit", "contrast_limit", "brightness_by_max") -class RandomBrightness(RandomBrightnessContrast): - """Randomly change brightness of the input image. - - Args: - limit: factor range for changing brightness. - If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2). - p: probability of applying the transform. Default: 0.5. - - Targets: - image - - Image types: - uint8, float32 - """ - - def __init__(self, limit: ScaleFloatType = 0.2, always_apply: bool = False, p: float = 0.5): - super().__init__(brightness_limit=limit, contrast_limit=0, always_apply=always_apply, p=p) - warnings.warn( - "This class has been deprecated. Please use RandomBrightnessContrast", - FutureWarning, - ) - - def get_transform_init_args(self) -> Dict[str, Any]: - return {"limit": self.brightness_limit} - - -class RandomContrast(RandomBrightnessContrast): - """Randomly change contrast of the input image. - - Args: - limit: factor range for changing contrast. - If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2). - p: probability of applying the transform. Default: 0.5. - - Targets: - image - - Image types: - uint8, float32 - """ - - def __init__(self, limit: ScaleFloatType = 0.2, always_apply: bool = False, p: float = 0.5): - super().__init__(brightness_limit=0, contrast_limit=limit, always_apply=always_apply, p=p) - warnings.warn( - f"{self.__class__.__name__} has been deprecated. Please use RandomBrightnessContrast", - FutureWarning, - ) - - def get_transform_init_args(self) -> Dict[str, ScaleFloatType]: - return {"limit": self.contrast_limit} - - class GaussNoise(ImageOnlyTransform): """Apply gaussian noise to the input image. @@ -1529,11 +1440,20 @@ def get_transform_init_args_names(self) -> Tuple[()]: class RandomGamma(ImageOnlyTransform): - """ - Args: - gamma_limit: If gamma_limit is a single float value, the range will be (-gamma_limit, gamma_limit). - Default: (80, 120). - eps: Deprecated. + """Applies random gamma correction to an image as a form of data augmentation. + + This class adjusts the luminance of an image by applying gamma correction with a randomly + selected gamma value from a specified range. Gamma correction can simulate various lighting + conditions, potentially enhancing model generalization. For more details on gamma correction, + see: https://en.wikipedia.org/wiki/Gamma_correction + + Attributes: + gamma_limit (Union[int, Tuple[int, int]]): The range for gamma adjustment. If `gamma_limit` is a single + int, the range will be interpreted as (-gamma_limit, gamma_limit), defining how much + to adjust the image's gamma. Default is (80, 120). + always_apply (bool): If `True`, the transform will always be applied, regardless of `p`. + Default is `False`. + p (float): The probability that the transform will be applied. Default is 0.5. Targets: image @@ -1545,13 +1465,11 @@ class RandomGamma(ImageOnlyTransform): def __init__( self, gamma_limit: ScaleIntType = (80, 120), - eps: Optional[Any] = None, always_apply: bool = False, p: float = 0.5, ): super().__init__(always_apply, p) self.gamma_limit = to_tuple(gamma_limit) - self.eps = eps def apply(self, img: np.ndarray, gamma: float = 1, **params: Any) -> np.ndarray: return F.gamma_transform(img, gamma=gamma) @@ -1559,8 +1477,8 @@ def apply(self, img: np.ndarray, gamma: float = 1, **params: Any) -> np.ndarray: def get_params(self) -> Dict[str, float]: return {"gamma": random.uniform(self.gamma_limit[0], self.gamma_limit[1]) / 100.0} - def get_transform_init_args_names(self) -> Tuple[str, str]: - return ("gamma_limit", "eps") + def get_transform_init_args_names(self) -> Tuple[str, ...]: + return ("gamma_limit",) class ToGray(ImageOnlyTransform): diff --git a/albumentations/core/keypoints_utils.py b/albumentations/core/keypoints_utils.py index ae9ca337e..a860d7609 100644 --- a/albumentations/core/keypoints_utils.py +++ b/albumentations/core/keypoints_utils.py @@ -94,27 +94,6 @@ def ensure_data_valid(self, data: Dict[str, Any]) -> None: "'keypoint_params' dict" ) - def ensure_transforms_valid(self, transforms: Sequence[object]) -> None: - # IAA-based augmentations supports only transformation of xy keypoints. - # If your keypoints formats is other than 'xy' we emit warning to let user - # be aware that angle and size will not be modified. - - try: - from albumentations.imgaug.transforms import DualIAATransform - except ImportError: - # imgaug is not installed so we skip imgaug checks. - return - - if self.params.format is not None and self.params.format != "xy": - for transform in transforms: - if isinstance(transform, DualIAATransform): - warnings.warn( - "{} transformation supports only 'xy' keypoints " - "augmentation. You have '{}' keypoints format. Scale " - "and angle WILL NOT BE transformed.".format(transform.__class__.__name__, self.params.format) - ) - break - def filter(self, data: Sequence[KeypointType], rows: int, cols: int) -> Sequence[KeypointType]: """ The function filters a sequence of data based on the number of rows and columns, and returns a diff --git a/albumentations/core/serialization.py b/albumentations/core/serialization.py index 974b424c8..95649a81e 100644 --- a/albumentations/core/serialization.py +++ b/albumentations/core/serialization.py @@ -140,9 +140,7 @@ def instantiate_nonserializable( def from_dict( - transform_dict: Dict[str, Any], - nonserializable: Optional[Dict[str, Any]] = None, - lambda_transforms: Union[Optional[Dict[str, Any]], str] = "deprecated", + transform_dict: Dict[str, Any], nonserializable: Optional[Dict[str, Any]] = None ) -> Optional[Serializable]: """ Args: @@ -151,12 +149,7 @@ def from_dict( This dictionary is required when you are restoring a pipeline that contains non-serializable transforms. Keys in that dictionary should be named same as `name` arguments in respective transforms from a serialized pipeline. - lambda_transforms (dict): Deprecated. Use 'nonserizalizable' instead. """ - if lambda_transforms != "deprecated": - warnings.warn("lambda_transforms argument is deprecated, please use 'nonserializable'", DeprecationWarning) - nonserializable = cast(Optional[Dict[str, Any]], lambda_transforms) - register_additional_transforms() transform = transform_dict["transform"] lmbd = instantiate_nonserializable(transform, nonserializable) diff --git a/albumentations/imgaug/__init__.py b/albumentations/imgaug/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/albumentations/imgaug/stubs.py b/albumentations/imgaug/stubs.py deleted file mode 100644 index 946b1164c..000000000 --- a/albumentations/imgaug/stubs.py +++ /dev/null @@ -1,83 +0,0 @@ -from typing import Any - -__all__ = [ - "IAAEmboss", - "IAASuperpixels", - "IAASharpen", - "IAAAdditiveGaussianNoise", - "IAACropAndPad", - "IAAFliplr", - "IAAFlipud", - "IAAAffine", - "IAAPiecewiseAffine", - "IAAPerspective", -] - - -class IAAStub: - def __init__(self, *args: Any, **kwargs: Any): - cls_name = self.__class__.__name__ - # Use getattr to safely access subclass attributes with a default value - doc_link = "https://albumentations.ai/docs/api_reference/augmentations" + getattr( - self, "doc_link", "/default_doc_link" - ) - alternative = getattr(self, "alternative", "DefaultAlternative") - raise RuntimeError( - f"You are trying to use a deprecated augmentation '{cls_name}' which depends on the imgaug library, " - f"but imgaug is not installed.\n\n" - "There are two options to fix this error:\n" - "1. [Recommended]. Switch to the Albumentations' implementation of the augmentation with the same API: " - f"{alternative} - {doc_link}\n" - "2. Install a version of Albumentations that contains imgaug by running " - "'pip install -U albumentations[imgaug]'." - ) - - -class IAACropAndPad(IAAStub): - alternative = "CropAndPad" - doc_link = "/crops/transforms/#albumentations.augmentations.crops.transforms.CropAndPad" - - -class IAAFliplr(IAAStub): - alternative = "HorizontalFlip" - doc_link = "/transforms/#albumentations.augmentations.transforms.HorizontalFlip" - - -class IAAFlipud(IAAStub): - alternative = "VerticalFlip" - doc_link = "/transforms/#albumentations.augmentations.transforms.VerticalFlip" - - -class IAAEmboss(IAAStub): - alternative = "Emboss" - doc_link = "/transforms/#albumentations.augmentations.transforms.Emboss" - - -class IAASuperpixels(IAAStub): - alternative = "Superpixels" - doc_link = "/transforms/#albumentations.augmentations.transforms.Superpixels" - - -class IAASharpen(IAAStub): - alternative = "Sharpen" - doc_link = "/transforms/#albumentations.augmentations.transforms.Sharpen" - - -class IAAAdditiveGaussianNoise(IAAStub): - alternative = "GaussNoise" - doc_link = "/transforms/#albumentations.augmentations.transforms.GaussNoise" - - -class IAAPiecewiseAffine(IAAStub): - alternative = "PiecewiseAffine" - doc_link = "/geometric/transforms/#albumentations.augmentations.geometric.transforms.PiecewiseAffine" - - -class IAAAffine(IAAStub): - alternative = "Affine" - doc_link = "/geometric/transforms/#albumentations.augmentations.geometric.transforms.Affine" - - -class IAAPerspective(IAAStub): - alternative = "Perspective" - doc_link = "/geometric/transforms/#albumentations.augmentations.geometric.transforms.Perspective" diff --git a/albumentations/imgaug/transforms.py b/albumentations/imgaug/transforms.py deleted file mode 100644 index 26c28c68d..000000000 --- a/albumentations/imgaug/transforms.py +++ /dev/null @@ -1,460 +0,0 @@ -try: - import imgaug as ia -except ImportError as e: - raise ImportError( - "You are trying to import an augmentation that depends on the imgaug library, but imgaug is not installed. To " - "install a version of Albumentations that contains imgaug please run 'pip install -U albumentations[imgaug]'" - ) from e - -try: - from imgaug import augmenters as iaa -except ImportError: - import imgaug.imgaug.augmenters as iaa - -import warnings -from typing import Any, Dict, Optional, Sequence, Tuple, Type, cast - -import numpy as np - -from albumentations.core.bbox_utils import ( - convert_bboxes_from_albumentations, - convert_bboxes_to_albumentations, -) -from albumentations.core.keypoints_utils import ( - convert_keypoints_from_albumentations, - convert_keypoints_to_albumentations, -) - -from ..augmentations import Perspective -from ..core.transforms_interface import ( - BasicTransform, - DualTransform, - ImageOnlyTransform, - to_tuple, -) -from ..core.types import BoxType, KeypointType, ScaleFloatType - -__all__ = [ - "BasicIAATransform", - "DualIAATransform", - "ImageOnlyIAATransform", - "IAAEmboss", - "IAASuperpixels", - "IAASharpen", - "IAAAdditiveGaussianNoise", - "IAACropAndPad", - "IAAFliplr", - "IAAFlipud", - "IAAAffine", - "IAAPiecewiseAffine", - "IAAPerspective", -] - - -class BasicIAATransform(BasicTransform): - def __init__(self, always_apply: bool = False, p: float = 0.5): - super().__init__(always_apply, p) - - @property - def processor(self) -> Type[iaa.Augmenter]: - return iaa.Noop() - - def update_params(self, params: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]: - params = super().update_params(params, **kwargs) - params["deterministic_processor"] = self.processor.to_deterministic() - return params - - def apply(self, img: np.ndarray, deterministic_processor: iaa.Augmenter, **params: Any) -> np.ndarray: - return deterministic_processor.augment_image(img) - - -class DualIAATransform(DualTransform, BasicIAATransform): - def apply_to_bboxes( - self, - bboxes: Sequence[BoxType], - deterministic_processor: iaa.Augmenter, - rows: int = 0, - cols: int = 0, - **params: Any, - ) -> Sequence[BoxType]: - if len(bboxes) > 0: - bboxes = convert_bboxes_from_albumentations(bboxes, "pascal_voc", rows=rows, cols=cols) - - bboxes_t = ia.BoundingBoxesOnImage([ia.BoundingBox(*bbox[:4]) for bbox in bboxes], (rows, cols)) - bboxes_t = deterministic_processor.augment_bounding_boxes([bboxes_t])[0].bounding_boxes - bboxes_t = [ - [bbox.x1, bbox.y1, bbox.x2, bbox.y2] + list(bbox_orig[4:]) - for (bbox, bbox_orig) in zip(bboxes_t, bboxes) - ] - - bboxes = convert_bboxes_to_albumentations(bboxes_t, "pascal_voc", rows=rows, cols=cols) - return bboxes - - """Applies transformation to keypoints. - Notes: - Since IAA supports only xy keypoints, scale and orientation will remain unchanged. - TODO: - Emit a warning message if child classes of DualIAATransform are instantiated - inside Compose with keypoints format other than 'xy'. - """ - - def apply_to_keypoints( - self, - keypoints: Sequence[KeypointType], - deterministic_processor: iaa.Augmenter, - rows: int = 0, - cols: int = 0, - **params: Any, - ) -> Sequence[KeypointType]: - if len(keypoints) > 0: - keypoints = convert_keypoints_from_albumentations(keypoints, "xy", rows=rows, cols=cols) - keypoints_t = ia.KeypointsOnImage([ia.Keypoint(*kp[:2]) for kp in keypoints], (rows, cols)) - keypoints_t = deterministic_processor.augment_keypoints([keypoints_t])[0].keypoints - - bboxes_t = [[kp.x, kp.y] + list(kp_orig[2:]) for (kp, kp_orig) in zip(keypoints_t, keypoints)] - - keypoints = convert_keypoints_to_albumentations( - cast(Sequence[KeypointType], bboxes_t), "xy", rows=rows, cols=cols - ) - return keypoints - - -class ImageOnlyIAATransform(ImageOnlyTransform, BasicIAATransform): - pass - - -class IAACropAndPad(DualIAATransform): - """This augmentation is deprecated. Please use CropAndPad instead.""" - - def __init__( - self, - px: Optional[float] = None, - percent: Optional[float] = None, - pad_mode: str = "constant", - pad_cval: float = 0, - keep_size: bool = True, - always_apply: bool = False, - p: float = 1, - ): - super().__init__(always_apply, p) - self.px = px - self.percent = percent - self.pad_mode = pad_mode - self.pad_cval = pad_cval - self.keep_size = keep_size - warnings.warn("IAACropAndPad is deprecated. Please use CropAndPad instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.CropAndPad(self.px, self.percent, self.pad_mode, self.pad_cval, self.keep_size) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return ("px", "percent", "pad_mode", "pad_cval", "keep_size") - - -class IAAFliplr(DualIAATransform): - """This augmentation is deprecated. Please use HorizontalFlip instead.""" - - def __init__(self, always_apply: bool = False, p: float = 0.5): - super().__init__(always_apply, p) - warnings.warn("IAAFliplr is deprecated. Please use HorizontalFlip instead.", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Fliplr(1) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return () - - -class IAAFlipud(DualIAATransform): - """This augmentation is deprecated. Please use VerticalFlip instead.""" - - def __init__(self, always_apply: bool = False, p: float = 0.5): - super().__init__(always_apply, p) - warnings.warn("IAAFlipud is deprecated. Please use VerticalFlip instead.", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Flipud(1) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return () - - -class IAAEmboss(ImageOnlyIAATransform): - """Emboss the input image and overlays the result with the original image. - This augmentation is deprecated. Please use Emboss instead. - - Args: - alpha ((float, float)): range to choose the visibility of the embossed image. At 0, only the original image is - visible,at 1.0 only its embossed version is visible. Default: (0.2, 0.5). - strength ((float, float)): strength range of the embossing. Default: (0.2, 0.7). - p (float): probability of applying the transform. Default: 0.5. - - Targets: - image - """ - - def __init__( - self, - alpha: Tuple[float, float] = (0.2, 0.5), - strength: Tuple[float, float] = (0.2, 0.7), - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.alpha = to_tuple(alpha, 0.0) - self.strength = to_tuple(strength, 0.0) - warnings.warn("This augmentation is deprecated. Please use Emboss instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Emboss(self.alpha, self.strength) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return "alpha", "strength" - - -class IAASuperpixels(ImageOnlyIAATransform): - """Completely or partially transform the input image to its superpixel representation. Uses skimage's version - of the SLIC algorithm. May be slow. - - This augmentation is deprecated. Please use Superpixels instead. - - Args: - p_replace (float): defines the probability of any superpixel area being replaced by the superpixel, i.e. by - the average pixel color within its area. Default: 0.1. - n_segments (int): target number of superpixels to generate. Default: 100. - p (float): probability of applying the transform. Default: 0.5. - - Targets: - image - """ - - def __init__(self, p_replace: float = 0.1, n_segments: int = 100, always_apply: bool = False, p: float = 0.5): - super().__init__(always_apply, p) - self.p_replace = p_replace - self.n_segments = n_segments - warnings.warn("IAASuperpixels is deprecated. Please use Superpixels instead.", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Superpixels(p_replace=self.p_replace, n_segments=self.n_segments) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return "p_replace", "n_segments" - - -class IAASharpen(ImageOnlyIAATransform): - """Sharpen the input image and overlays the result with the original image. - This augmentation is deprecated. Please use Sharpen instead - Args: - alpha ((float, float)): range to choose the visibility of the sharpened image. At 0, only the original image is - visible, at 1.0 only its sharpened version is visible. Default: (0.2, 0.5). - lightness ((float, float)): range to choose the lightness of the sharpened image. Default: (0.5, 1.0). - p (float): probability of applying the transform. Default: 0.5. - - Targets: - image - """ - - def __init__( - self, - alpha: Tuple[float, float] = (0.2, 0.5), - lightness: Tuple[float, float] = (0.5, 1.0), - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.alpha = to_tuple(alpha, 0) - self.lightness = to_tuple(lightness, 0) - warnings.warn("IAASharpen is deprecated. Please use Sharpen instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Sharpen(self.alpha, self.lightness) - - def get_transform_init_args_names(self) -> Tuple[str, str]: - return "alpha", "lightness" - - -class IAAAdditiveGaussianNoise(ImageOnlyIAATransform): - """Add gaussian noise to the input image. - - This augmentation is deprecated. Please use GaussNoise instead. - - Args: - loc: mean of the normal distribution that generates the noise. Default: 0. - scale: standard deviation of the normal distribution that generates the noise. - Default: (0.01 * 255, 0.05 * 255). - p (float): probability of applying the transform. Default: 0.5. - - Targets: - image - """ - - def __init__( - self, - loc: int = 0, - scale: Tuple[float, float] = (0.01 * 255, 0.05 * 255), - per_channel: bool = False, - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.loc = loc - self.scale = to_tuple(scale, 0.0) - self.per_channel = per_channel - warnings.warn("IAAAdditiveGaussianNoise is deprecated. Please use GaussNoise instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.AdditiveGaussianNoise(self.loc, self.scale, self.per_channel) - - def get_transform_init_args_names(self) -> Tuple[str, str, str]: - return "loc", "scale", "per_channel" - - -class IAAPiecewiseAffine(DualIAATransform): - """Place a regular grid of points on the input and randomly move the neighborhood of these point around - via affine transformations. - - This augmentation is deprecated. Please use PiecewiseAffine instead. - - Note: This class introduce interpolation artifacts to mask if it has values other than {0;1} - - Args: - scale: factor range that determines how far each point is moved. Default: (0.03, 0.05). - nb_rows: number of rows of points that the regular grid should have. Default: 4. - nb_cols: number of columns of points that the regular grid should have. Default: 4. - p: probability of applying the transform. Default: 0.5. - - Targets: - image, mask - """ - - def __init__( - self, - scale: Tuple[float, float] = (0.03, 0.05), - nb_rows: int = 4, - nb_cols: int = 4, - order: int = 1, - cval: int = 0, - mode: str = "constant", - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.scale = to_tuple(scale, 0.0) - self.nb_rows = nb_rows - self.nb_cols = nb_cols - self.order = order - self.cval = cval - self.mode = mode - warnings.warn("This IAAPiecewiseAffine is deprecated. Please use PiecewiseAffine instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.PiecewiseAffine(self.scale, self.nb_rows, self.nb_cols, self.order, self.cval, self.mode) - - def get_transform_init_args_names(self) -> Tuple[str, str, str, str, str, str]: - return ("scale", "nb_rows", "nb_cols", "order", "cval", "mode") - - -class IAAAffine(DualIAATransform): - """Place a regular grid of points on the input and randomly move the neighborhood of these point around - via affine transformations. - - This augmentation is deprecated. Please use Affine instead. - - Note: This class introduce interpolation artifacts to mask if it has values other than {0;1} - - Args: - p: probability of applying the transform. Default: 0.5. - - Targets: - image, mask - """ - - def __init__( - self, - scale: float = 1, - translate_percent: Optional[float] = None, - translate_px: Optional[float] = None, - rotate: float = 0.0, - shear: float = 0.0, - order: int = 1, - cval: float = 0, - mode: str = "reflect", - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) - self.scale = to_tuple(scale, 1.0) - if translate_percent is None: - self.translate_percent = None - else: - self.translate_percent = to_tuple(translate_percent, 0) - - if translate_px is None: - self.translate_px = None - else: - self.translate_px = to_tuple(translate_px, 0) - self.rotate = to_tuple(rotate) - self.shear = to_tuple(shear) - self.order = order - self.cval = cval - self.mode = mode - warnings.warn("This IAAAffine is deprecated. Please use Affine instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.Affine( - self.scale, - self.translate_percent, - self.translate_px, - self.rotate, - self.shear, - self.order, - self.cval, - self.mode, - ) - - def get_transform_init_args_names(self) -> Tuple[str, ...]: - return ("scale", "translate_percent", "translate_px", "rotate", "shear", "order", "cval", "mode") - - -class IAAPerspective(Perspective): - """Perform a random four point perspective transform of the input. - This augmentation is deprecated. Please use Perspective instead. - - Note: This class introduce interpolation artifacts to mask if it has values other than {0;1} - - Args: - scale: standard deviation of the normal distributions. These are used to sample - the random distances of the subimage's corners from the full image's corners. Default: (0.05, 0.1). - p: probability of applying the transform. Default: 0.5. - - Targets: - image, mask - """ - - def __init__( - self, - scale: ScaleFloatType = (0.05, 0.1), - keep_size: bool = True, - always_apply: bool = False, - p: float = 0.5, - ): - super().__init__(always_apply, p) # type: ignore[arg-type] - self.scale = to_tuple(scale, 1.0) - self.keep_size = keep_size - warnings.warn("This IAAPerspective is deprecated. Please use Perspective instead", FutureWarning) - - @property - def processor(self) -> np.ndarray: - return iaa.PerspectiveTransform(self.scale, keep_size=self.keep_size) - - def get_transform_init_args_names(self) -> Tuple[str, str]: - return "scale", "keep_size" diff --git a/albumentations/pytorch/functional.py b/albumentations/pytorch/functional.py deleted file mode 100644 index 8d67fe323..000000000 --- a/albumentations/pytorch/functional.py +++ /dev/null @@ -1,31 +0,0 @@ -from typing import Optional - -import numpy as np -import torch -import torchvision.transforms.functional as F - - -def img_to_tensor(image: np.ndarray, normalize: Optional[bool] = None) -> torch.Tensor: - tensor = torch.from_numpy(np.moveaxis(image / (255.0 if image.dtype == np.uint8 else 1), -1, 0).astype(np.float32)) - if normalize is not None: - return F.normalize(tensor, **normalize) - return tensor - - -def mask_to_tensor(mask: np.ndarray, num_classes: int, sigmoid: bool) -> torch.Tensor: - if num_classes > 1: - if not sigmoid: - # softmax - long_mask = np.zeros((mask.shape[:2]), dtype=np.int64) - if len(mask.shape) == 3: - for c in range(mask.shape[2]): - long_mask[mask[..., c] > 0] = c - else: - long_mask[mask > 127] = 1 - long_mask[mask == 0] = 0 - mask = long_mask - else: - mask = np.moveaxis(mask / (255.0 if mask.dtype == np.uint8 else 1), -1, 0).astype(np.float32) - else: - mask = np.expand_dims(mask / (255.0 if mask.dtype == np.uint8 else 1), 0).astype(np.float32) - return torch.from_numpy(mask) diff --git a/albumentations/pytorch/transforms.py b/albumentations/pytorch/transforms.py index bfcb9a2fd..a3bf291c6 100644 --- a/albumentations/pytorch/transforms.py +++ b/albumentations/pytorch/transforms.py @@ -1,72 +1,21 @@ -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Tuple import numpy as np import torch -from torchvision.transforms import functional as F from ..core.transforms_interface import BasicTransform __all__ = ["ToTensorV2"] -def img_to_tensor(im: np.ndarray, normalize: Optional[bool] = None) -> torch.Tensor: - tensor = torch.from_numpy(np.moveaxis(im / (255.0 if im.dtype == np.uint8 else 1), -1, 0).astype(np.float32)) - if normalize is not None: - return F.normalize(tensor, **normalize) - return tensor - - -def mask_to_tensor(mask: np.ndarray, num_classes: int, sigmoid: bool) -> torch.Tensor: - if num_classes > 1: - if not sigmoid: - # softmax - long_mask = np.zeros((mask.shape[:2]), dtype=np.int64) - if len(mask.shape) == 3: - for c in range(mask.shape[2]): - long_mask[mask[..., c] > 0] = c - else: - long_mask[mask > 127] = 1 - long_mask[mask == 0] = 0 - mask = long_mask - else: - mask = np.moveaxis(mask / (255.0 if mask.dtype == np.uint8 else 1), -1, 0).astype(np.float32) - else: - mask = np.expand_dims(mask / (255.0 if mask.dtype == np.uint8 else 1), 0).astype(np.float32) - return torch.from_numpy(mask) - - -class ToTensor(BasicTransform): - """Convert image and mask to `torch.Tensor` and divide by 255 if image or mask are `uint8` type. - This transform is now removed from Albumentations. If you need it downgrade the library to version 0.5.2. - - Args: - num_classes (int): only for segmentation - sigmoid (bool, optional): only for segmentation, transform mask to LongTensor or not. - normalize (dict, optional): dict with keys [mean, std] to pass it into torchvision.normalize - - """ - - def __init__(self, num_classes: int = 1, sigmoid: bool = True, normalize: Optional[bool] = None): - raise RuntimeError( - "`ToTensor` is obsolete and it was removed from Albumentations. Please use `ToTensorV2` instead - " - "https://albumentations.ai/docs/api_reference/pytorch/transforms/" - "#albumentations.pytorch.transforms.ToTensorV2. " - "\n\nIf you need `ToTensor` downgrade Albumentations to version 0.5.2." - ) - - class ToTensorV2(BasicTransform): - """Convert image and mask to `torch.Tensor`. The numpy `HWC` image is converted to pytorch `CHW` tensor. - If the image is in `HW` format (grayscale image), it will be converted to pytorch `HW` tensor. - This is a simplified and improved version of the old `ToTensor` - transform (`ToTensor` was deprecated, and now it is not present in Albumentations. You should use `ToTensorV2` - instead). + """Converts images/masks to PyTorch Tensors, inheriting from BasicTransform. Supports images in numpy `HWC` format + and converts them to PyTorch `CHW` format. If the image is in `HW` format, it will be converted to PyTorch `HW`. - Args: - transpose_mask (bool): If True and an input mask has three dimensions, this transform will transpose dimensions - so the shape `[height, width, num_channels]` becomes `[num_channels, height, width]`. The latter format is a - standard format for PyTorch Tensors. Default: False. - always_apply (bool): Indicates whether this transformation should be always applied. Default: True. + Attributes: + transpose_mask (bool): If True, transposes 3D input mask dimensions from `[height, width, num_channels]` to + `[num_channels, height, width]`. + always_apply (bool): Indicates if this transformation should be always applied. Default: True. p (float): Probability of applying the transform. Default: 1.0. """ diff --git a/setup.py b/setup.py index 2ee475989..e43e71fd2 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,16 @@ -import io import os import re from pkg_resources import DistributionNotFound, get_distribution from setuptools import find_packages, setup -INSTALL_REQUIRES = ["numpy>=1.11.1", "scipy>=1.1.0", "scikit-image>=0.16.1", "PyYAML", "qudida>=0.0.4"] +INSTALL_REQUIRES = ["numpy>=1.24.4", "scipy>=1.10.0", "scikit-image>=0.21.0", "PyYAML", "qudida>=0.0.4"] # If none of packages in first installed, install second package CHOOSE_INSTALL_REQUIRES = [ ( - ("opencv-python>=4.1.1", "opencv-contrib-python>=4.1.1", "opencv-contrib-python-headless>=4.1.1"), - "opencv-python-headless>=4.1.1", + ("opencv-python>=4.9.0", "opencv-contrib-python>=4.9.0", "opencv-contrib-python-headless>=4.9.0"), + "opencv-python-headless>=4.9.0", ) ] @@ -19,13 +18,13 @@ def get_version(): current_dir = os.path.abspath(os.path.dirname(__file__)) version_file = os.path.join(current_dir, "albumentations", "__init__.py") - with io.open(version_file, encoding="utf-8") as f: + with open(version_file, encoding="utf-8") as f: return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', f.read(), re.M).group(1) def get_long_description(): base_dir = os.path.abspath(os.path.dirname(__file__)) - with io.open(os.path.join(base_dir, "README.md"), encoding="utf-8") as f: + with open(os.path.join(base_dir, "README.md"), encoding="utf-8") as f: return f.read() @@ -60,13 +59,13 @@ def get_install_requirements(install_requires, choose_install_requires): description="Fast image augmentation library and easy to use wrapper around other libraries", long_description=get_long_description(), long_description_content_type="text/markdown", - author="Buslaev Alexander, Alexander Parinov, Vladimir Iglovikov, Eugene Khvedchenya, Druzhinin Mikhail", + author="Vladimir I. Iglovikov, Mikhail Druzhinin, Alex Parinov, Alexander Buslaev, Eugene Khvedchenya", license="MIT", url="https://github.com/albumentations-team/albumentations", packages=find_packages(exclude=["tests"]), - python_requires=">=3.7", + python_requires=">=3.8", install_requires=get_install_requirements(INSTALL_REQUIRES, CHOOSE_INSTALL_REQUIRES), - extras_require={"tests": ["pytest"], "imgaug": ["imgaug>=0.4.0"], "develop": ["pytest", "imgaug>=0.4.0"]}, + extras_require={"tests": ["pytest"], "develop": ["pytest"]}, classifiers=[ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", diff --git a/tests/conftest.py b/tests/conftest.py index 85623a2b1..6b26c6d93 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,18 +14,6 @@ torch_available = False -try: - import imgaug - - imgaug_available = True -except ImportError: - imgaug_available = False - - -skipif_imgaug = pytest.mark.skipif(imgaug_available, reason="The test was skipped because imgaug is installed") -skipif_no_imgaug = pytest.mark.skipif( - not imgaug_available, reason="The test was skipped because imgaug is not installed" -) skipif_no_torch = pytest.mark.skipif( not torch_available, reason="The test was skipped because PyTorch and torchvision are not installed" ) @@ -40,10 +28,6 @@ def pytest_ignore_collect(path): ) return True - if not imgaug_available and path.fnmatch("test_imgaug.py"): - warnings.warn(UserWarning("Tests that require imgaug were skipped because this library is not installed.")) - return True - return False diff --git a/tests/files/transform_serialization_v2_with_totensor.json b/tests/files/transform_serialization_v2_with_totensor.json index 95da79d0d..510d1bda5 100644 --- a/tests/files/transform_serialization_v2_with_totensor.json +++ b/tests/files/transform_serialization_v2_with_totensor.json @@ -1 +1,507 @@ -{"__version__": "0.5.2", "transform": {"__class_fullname__": "Compose", "p": 1.0, "transforms": [{"__class_fullname__": "Blur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "CLAHE", "always_apply": false, "p": 0.5, "clip_limit": [1, 4.0], "tile_grid_size": [8, 8]}, {"__class_fullname__": "ChannelDropout", "always_apply": false, "p": 0.5, "channel_drop_range": [1, 1], "fill_value": 0}, {"__class_fullname__": "ChannelShuffle", "always_apply": false, "p": 0.5}, {"__class_fullname__": "CoarseDropout", "always_apply": false, "p": 0.5, "max_holes": 8, "max_height": 8, "max_width": 8, "min_holes": 8, "min_height": 8, "min_width": 8, "fill_value": 0, "mask_fill_value": null}, {"__class_fullname__": "Downscale", "always_apply": false, "p": 0.5, "scale_min": 0.25, "scale_max": 0.25, "interpolation": 0}, {"__class_fullname__": "ElasticTransform", "always_apply": false, "p": 0.5, "alpha": 1, "sigma": 50, "alpha_affine": 50, "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null, "approximate": false}, {"__class_fullname__": "Equalize", "always_apply": false, "p": 0.5, "mode": "cv", "by_channels": true}, {"__class_fullname__": "FancyPCA", "always_apply": false, "p": 0.5, "alpha": 0.1}, {"__class_fullname__": "Flip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "GaussNoise", "always_apply": false, "p": 0.5, "var_limit": [10.0, 50.0]}, {"__class_fullname__": "GaussianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7], "sigma_limit": [0, 0]}, {"__class_fullname__": "GlassBlur", "always_apply": false, "p": 0.5, "sigma": 0.7, "max_delta": 4, "iterations": 2}, {"__class_fullname__": "GridDistortion", "always_apply": false, "p": 0.5, "num_steps": 5, "distort_limit": [-0.3, 0.3], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "HorizontalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "HueSaturationValue", "always_apply": false, "p": 0.5, "hue_shift_limit": [-20, 20], "sat_shift_limit": [-30, 30], "val_shift_limit": [-20, 20]}, {"__class_fullname__": "ISONoise", "always_apply": false, "p": 0.5, "intensity": [0.1, 0.5], "color_shift": [0.01, 0.05]}, {"__class_fullname__": "ImageCompression", "always_apply": false, "p": 0.5, "quality_lower": 99, "quality_upper": 100, "compression_type": 0}, {"__class_fullname__": "InvertImg", "always_apply": false, "p": 0.5}, {"__class_fullname__": "LongestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "MedianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "MotionBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "MultiplicativeNoise", "always_apply": false, "p": 0.5, "multiplier": [0.9, 1.1], "per_channel": false, "elementwise": false}, {"__class_fullname__": "NoOp", "always_apply": false, "p": 0.5}, {"__class_fullname__": "OpticalDistortion", "always_apply": false, "p": 0.5, "distort_limit": [-0.05, 0.05], "shift_limit": [-0.05, 0.05], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "PadIfNeeded", "always_apply": false, "p": 1.0, "min_height": 1024, "min_width": 1024, "pad_height_divisor": null, "pad_width_divisor": null, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "Posterize", "always_apply": false, "p": 0.5, "num_bits": [4, 4]}, {"__class_fullname__": "RGBShift", "always_apply": false, "p": 0.5, "r_shift_limit": [-20, 20], "g_shift_limit": [-20, 20], "b_shift_limit": [-20, 20]}, {"__class_fullname__": "RandomBrightnessContrast", "always_apply": false, "p": 0.5, "brightness_limit": [-0.2, 0.2], "contrast_limit": [-0.2, 0.2], "brightness_by_max": true}, {"__class_fullname__": "RandomFog", "always_apply": false, "p": 0.5, "fog_coef_lower": 0.3, "fog_coef_upper": 1, "alpha_coef": 0.08}, {"__class_fullname__": "RandomGamma", "always_apply": false, "p": 0.5, "gamma_limit": [80, 120], "eps": null}, {"__class_fullname__": "RandomGridShuffle", "always_apply": false, "p": 0.5, "grid": [3, 3]}, {"__class_fullname__": "RandomRain", "always_apply": false, "p": 0.5, "slant_lower": -10, "slant_upper": 10, "drop_length": 20, "drop_width": 1, "drop_color": [200, 200, 200], "blur_value": 7, "brightness_coefficient": 0.7, "rain_type": null}, {"__class_fullname__": "RandomRotate90", "always_apply": false, "p": 0.5}, {"__class_fullname__": "RandomScale", "always_apply": false, "p": 0.5, "interpolation": 1, "scale_limit": [-0.09999999999999998, 0.10000000000000009]}, {"__class_fullname__": "RandomShadow", "always_apply": false, "p": 0.5, "shadow_roi": [0, 0.5, 1, 1], "num_shadows_lower": 1, "num_shadows_upper": 2, "shadow_dimension": 5}, {"__class_fullname__": "RandomSnow", "always_apply": false, "p": 0.5, "snow_point_lower": 0.1, "snow_point_upper": 0.3, "brightness_coeff": 2.5}, {"__class_fullname__": "RandomSunFlare", "always_apply": false, "p": 0.5, "flare_roi": [0, 0, 1, 0.5], "angle_lower": 0, "angle_upper": 1, "num_flare_circles_lower": 6, "num_flare_circles_upper": 10, "src_radius": 400, "src_color": [255, 255, 255]}, {"__class_fullname__": "Rotate", "always_apply": false, "p": 0.5, "limit": [-90, 90], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "ShiftScaleRotate", "always_apply": false, "p": 0.5, "shift_limit_x": [-0.0625, 0.0625], "shift_limit_y": [-0.0625, 0.0625], "scale_limit": [-0.09999999999999998, 0.10000000000000009], "rotate_limit": [-45, 45], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "SmallestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "Solarize", "always_apply": false, "p": 0.5, "threshold": [128, 128]}, {"__class_fullname__": "ToGray", "always_apply": false, "p": 0.5}, {"__class_fullname__": "ToSepia", "always_apply": false, "p": 0.5}, {"__class_fullname__": "Transpose", "always_apply": false, "p": 0.5}, {"__class_fullname__": "VerticalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "RandomCrop", "always_apply": false, "p": 1.0, "height": 32, "width": 32}, {"__class_fullname__": "Normalize", "always_apply": false, "p": 1.0, "mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225], "max_pixel_value": 255.0}, {"__class_fullname__": "ToTensorV2", "always_apply": true, "p": 1.0, "transpose_mask": false}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}}} +{ + "__version__": "0.5.2", + "transform": { + "__class_fullname__": "Compose", + "p": 1.0, + "transforms": [ + { + "__class_fullname__": "Blur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "CLAHE", + "always_apply": false, + "p": 0.5, + "clip_limit": [ + 1, + 4.0 + ], + "tile_grid_size": [ + 8, + 8 + ] + }, + { + "__class_fullname__": "ChannelDropout", + "always_apply": false, + "p": 0.5, + "channel_drop_range": [ + 1, + 1 + ], + "fill_value": 0 + }, + { + "__class_fullname__": "ChannelShuffle", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "CoarseDropout", + "always_apply": false, + "p": 0.5, + "max_holes": 8, + "max_height": 8, + "max_width": 8, + "min_holes": 8, + "min_height": 8, + "min_width": 8, + "fill_value": 0, + "mask_fill_value": null + }, + { + "__class_fullname__": "Downscale", + "always_apply": false, + "p": 0.5, + "scale_min": 0.25, + "scale_max": 0.25, + "interpolation": 0 + }, + { + "__class_fullname__": "ElasticTransform", + "always_apply": false, + "p": 0.5, + "alpha": 1, + "sigma": 50, + "alpha_affine": 50, + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null, + "approximate": false + }, + { + "__class_fullname__": "Equalize", + "always_apply": false, + "p": 0.5, + "mode": "cv", + "by_channels": true + }, + { + "__class_fullname__": "FancyPCA", + "always_apply": false, + "p": 0.5, + "alpha": 0.1 + }, + { + "__class_fullname__": "Flip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "GaussNoise", + "always_apply": false, + "p": 0.5, + "var_limit": [ + 10.0, + 50.0 + ] + }, + { + "__class_fullname__": "GaussianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ], + "sigma_limit": [ + 0, + 0 + ] + }, + { + "__class_fullname__": "GlassBlur", + "always_apply": false, + "p": 0.5, + "sigma": 0.7, + "max_delta": 4, + "iterations": 2 + }, + { + "__class_fullname__": "GridDistortion", + "always_apply": false, + "p": 0.5, + "num_steps": 5, + "distort_limit": [ + -0.3, + 0.3 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "HorizontalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "HueSaturationValue", + "always_apply": false, + "p": 0.5, + "hue_shift_limit": [ + -20, + 20 + ], + "sat_shift_limit": [ + -30, + 30 + ], + "val_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "ISONoise", + "always_apply": false, + "p": 0.5, + "intensity": [ + 0.1, + 0.5 + ], + "color_shift": [ + 0.01, + 0.05 + ] + }, + { + "__class_fullname__": "ImageCompression", + "always_apply": false, + "p": 0.5, + "quality_lower": 99, + "quality_upper": 100, + "compression_type": 0 + }, + { + "__class_fullname__": "InvertImg", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "LongestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "MedianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "MotionBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "MultiplicativeNoise", + "always_apply": false, + "p": 0.5, + "multiplier": [ + 0.9, + 1.1 + ], + "per_channel": false, + "elementwise": false + }, + { + "__class_fullname__": "NoOp", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "OpticalDistortion", + "always_apply": false, + "p": 0.5, + "distort_limit": [ + -0.05, + 0.05 + ], + "shift_limit": [ + -0.05, + 0.05 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "PadIfNeeded", + "always_apply": false, + "p": 1.0, + "min_height": 1024, + "min_width": 1024, + "pad_height_divisor": null, + "pad_width_divisor": null, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "Posterize", + "always_apply": false, + "p": 0.5, + "num_bits": [ + 4, + 4 + ] + }, + { + "__class_fullname__": "RGBShift", + "always_apply": false, + "p": 0.5, + "r_shift_limit": [ + -20, + 20 + ], + "g_shift_limit": [ + -20, + 20 + ], + "b_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "RandomBrightnessContrast", + "always_apply": false, + "p": 0.5, + "brightness_limit": [ + -0.2, + 0.2 + ], + "contrast_limit": [ + -0.2, + 0.2 + ], + "brightness_by_max": true + }, + { + "__class_fullname__": "RandomFog", + "always_apply": false, + "p": 0.5, + "fog_coef_lower": 0.3, + "fog_coef_upper": 1, + "alpha_coef": 0.08 + }, + { + "__class_fullname__": "RandomGamma", + "always_apply": false, + "p": 0.5, + "gamma_limit": [ + 80, + 120 + ] + }, + { + "__class_fullname__": "RandomGridShuffle", + "always_apply": false, + "p": 0.5, + "grid": [ + 3, + 3 + ] + }, + { + "__class_fullname__": "RandomRain", + "always_apply": false, + "p": 0.5, + "slant_lower": -10, + "slant_upper": 10, + "drop_length": 20, + "drop_width": 1, + "drop_color": [ + 200, + 200, + 200 + ], + "blur_value": 7, + "brightness_coefficient": 0.7, + "rain_type": null + }, + { + "__class_fullname__": "RandomRotate90", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "RandomScale", + "always_apply": false, + "p": 0.5, + "interpolation": 1, + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ] + }, + { + "__class_fullname__": "RandomShadow", + "always_apply": false, + "p": 0.5, + "shadow_roi": [ + 0, + 0.5, + 1, + 1 + ], + "num_shadows_lower": 1, + "num_shadows_upper": 2, + "shadow_dimension": 5 + }, + { + "__class_fullname__": "RandomSnow", + "always_apply": false, + "p": 0.5, + "snow_point_lower": 0.1, + "snow_point_upper": 0.3, + "brightness_coeff": 2.5 + }, + { + "__class_fullname__": "RandomSunFlare", + "always_apply": false, + "p": 0.5, + "flare_roi": [ + 0, + 0, + 1, + 0.5 + ], + "angle_lower": 0, + "angle_upper": 1, + "num_flare_circles_lower": 6, + "num_flare_circles_upper": 10, + "src_radius": 400, + "src_color": [ + 255, + 255, + 255 + ] + }, + { + "__class_fullname__": "Rotate", + "always_apply": false, + "p": 0.5, + "limit": [ + -90, + 90 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "ShiftScaleRotate", + "always_apply": false, + "p": 0.5, + "shift_limit_x": [ + -0.0625, + 0.0625 + ], + "shift_limit_y": [ + -0.0625, + 0.0625 + ], + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ], + "rotate_limit": [ + -45, + 45 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "SmallestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "Solarize", + "always_apply": false, + "p": 0.5, + "threshold": [ + 128, + 128 + ] + }, + { + "__class_fullname__": "ToGray", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "ToSepia", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "Transpose", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "VerticalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "RandomCrop", + "always_apply": false, + "p": 1.0, + "height": 32, + "width": 32 + }, + { + "__class_fullname__": "Normalize", + "always_apply": false, + "p": 1.0, + "mean": [ + 0.485, + 0.456, + 0.406 + ], + "std": [ + 0.229, + 0.224, + 0.225 + ], + "max_pixel_value": 255.0 + }, + { + "__class_fullname__": "ToTensorV2", + "always_apply": true, + "p": 1.0, + "transpose_mask": false + } + ], + "bbox_params": null, + "keypoint_params": null, + "additional_targets": {} + } +} diff --git a/tests/files/transform_serialization_v2_without_totensor.json b/tests/files/transform_serialization_v2_without_totensor.json index 4b4643780..ab91b3606 100644 --- a/tests/files/transform_serialization_v2_without_totensor.json +++ b/tests/files/transform_serialization_v2_without_totensor.json @@ -1 +1,503 @@ -{"__version__": "0.5.2", "transform": {"__class_fullname__": "Compose", "p": 1.0, "transforms": [{"__class_fullname__": "Blur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "CLAHE", "always_apply": false, "p": 0.5, "clip_limit": [1, 4.0], "tile_grid_size": [8, 8]}, {"__class_fullname__": "ChannelDropout", "always_apply": false, "p": 0.5, "channel_drop_range": [1, 1], "fill_value": 0}, {"__class_fullname__": "ChannelShuffle", "always_apply": false, "p": 0.5}, {"__class_fullname__": "CoarseDropout", "always_apply": false, "p": 0.5, "max_holes": 8, "max_height": 8, "max_width": 8, "min_holes": 8, "min_height": 8, "min_width": 8, "fill_value": 0, "mask_fill_value": null}, {"__class_fullname__": "Downscale", "always_apply": false, "p": 0.5, "scale_min": 0.25, "scale_max": 0.25, "interpolation": 0}, {"__class_fullname__": "ElasticTransform", "always_apply": false, "p": 0.5, "alpha": 1, "sigma": 50, "alpha_affine": 50, "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null, "approximate": false}, {"__class_fullname__": "Equalize", "always_apply": false, "p": 0.5, "mode": "cv", "by_channels": true}, {"__class_fullname__": "FancyPCA", "always_apply": false, "p": 0.5, "alpha": 0.1}, {"__class_fullname__": "Flip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "GaussNoise", "always_apply": false, "p": 0.5, "var_limit": [10.0, 50.0], "per_channel": true, "mean": 0}, {"__class_fullname__": "GaussianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7], "sigma_limit": [0, 0]}, {"__class_fullname__": "GlassBlur", "always_apply": false, "p": 0.5, "sigma": 0.7, "max_delta": 4, "iterations": 2}, {"__class_fullname__": "GridDistortion", "always_apply": false, "p": 0.5, "num_steps": 5, "distort_limit": [-0.3, 0.3], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "HorizontalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "HueSaturationValue", "always_apply": false, "p": 0.5, "hue_shift_limit": [-20, 20], "sat_shift_limit": [-30, 30], "val_shift_limit": [-20, 20]}, {"__class_fullname__": "ISONoise", "always_apply": false, "p": 0.5, "intensity": [0.1, 0.5], "color_shift": [0.01, 0.05]}, {"__class_fullname__": "ImageCompression", "always_apply": false, "p": 0.5, "quality_lower": 99, "quality_upper": 100, "compression_type": 0}, {"__class_fullname__": "InvertImg", "always_apply": false, "p": 0.5}, {"__class_fullname__": "LongestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "MedianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "MotionBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "MultiplicativeNoise", "always_apply": false, "p": 0.5, "multiplier": [0.9, 1.1], "per_channel": false, "elementwise": false}, {"__class_fullname__": "NoOp", "always_apply": false, "p": 0.5}, {"__class_fullname__": "OpticalDistortion", "always_apply": false, "p": 0.5, "distort_limit": [-0.05, 0.05], "shift_limit": [-0.05, 0.05], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "PadIfNeeded", "always_apply": false, "p": 1.0, "min_height": 1024, "min_width": 1024, "pad_height_divisor": null, "pad_width_divisor": null, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "Posterize", "always_apply": false, "p": 0.5, "num_bits": [4, 4]}, {"__class_fullname__": "RGBShift", "always_apply": false, "p": 0.5, "r_shift_limit": [-20, 20], "g_shift_limit": [-20, 20], "b_shift_limit": [-20, 20]}, {"__class_fullname__": "RandomBrightnessContrast", "always_apply": false, "p": 0.5, "brightness_limit": [-0.2, 0.2], "contrast_limit": [-0.2, 0.2], "brightness_by_max": true}, {"__class_fullname__": "RandomFog", "always_apply": false, "p": 0.5, "fog_coef_lower": 0.3, "fog_coef_upper": 1, "alpha_coef": 0.08}, {"__class_fullname__": "RandomGamma", "always_apply": false, "p": 0.5, "gamma_limit": [80, 120], "eps": null}, {"__class_fullname__": "RandomGridShuffle", "always_apply": false, "p": 0.5, "grid": [3, 3]}, {"__class_fullname__": "RandomRain", "always_apply": false, "p": 0.5, "slant_lower": -10, "slant_upper": 10, "drop_length": 20, "drop_width": 1, "drop_color": [200, 200, 200], "blur_value": 7, "brightness_coefficient": 0.7, "rain_type": null}, {"__class_fullname__": "RandomRotate90", "always_apply": false, "p": 0.5}, {"__class_fullname__": "RandomScale", "always_apply": false, "p": 0.5, "interpolation": 1, "scale_limit": [-0.09999999999999998, 0.10000000000000009]}, {"__class_fullname__": "RandomShadow", "always_apply": false, "p": 0.5, "shadow_roi": [0, 0.5, 1, 1], "num_shadows_lower": 1, "num_shadows_upper": 2, "shadow_dimension": 5}, {"__class_fullname__": "RandomSnow", "always_apply": false, "p": 0.5, "snow_point_lower": 0.1, "snow_point_upper": 0.3, "brightness_coeff": 2.5}, {"__class_fullname__": "RandomSunFlare", "always_apply": false, "p": 0.5, "flare_roi": [0, 0, 1, 0.5], "angle_lower": 0, "angle_upper": 1, "num_flare_circles_lower": 6, "num_flare_circles_upper": 10, "src_radius": 400, "src_color": [255, 255, 255]}, {"__class_fullname__": "Rotate", "always_apply": false, "p": 0.5, "limit": [-90, 90], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "ShiftScaleRotate", "always_apply": false, "p": 0.5, "shift_limit_x": [-0.0625, 0.0625], "shift_limit_y": [-0.0625, 0.0625], "scale_limit": [-0.09999999999999998, 0.10000000000000009], "rotate_limit": [-45, 45], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "SmallestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "Solarize", "always_apply": false, "p": 0.5, "threshold": [128, 128]}, {"__class_fullname__": "ToGray", "always_apply": false, "p": 0.5}, {"__class_fullname__": "ToSepia", "always_apply": false, "p": 0.5}, {"__class_fullname__": "Transpose", "always_apply": false, "p": 0.5}, {"__class_fullname__": "VerticalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "RandomCrop", "always_apply": false, "p": 1.0, "height": 32, "width": 32}, {"__class_fullname__": "Normalize", "always_apply": false, "p": 1.0, "mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225], "max_pixel_value": 255.0}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}}} +{ + "__version__": "0.5.2", + "transform": { + "__class_fullname__": "Compose", + "p": 1.0, + "transforms": [ + { + "__class_fullname__": "Blur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "CLAHE", + "always_apply": false, + "p": 0.5, + "clip_limit": [ + 1, + 4.0 + ], + "tile_grid_size": [ + 8, + 8 + ] + }, + { + "__class_fullname__": "ChannelDropout", + "always_apply": false, + "p": 0.5, + "channel_drop_range": [ + 1, + 1 + ], + "fill_value": 0 + }, + { + "__class_fullname__": "ChannelShuffle", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "CoarseDropout", + "always_apply": false, + "p": 0.5, + "max_holes": 8, + "max_height": 8, + "max_width": 8, + "min_holes": 8, + "min_height": 8, + "min_width": 8, + "fill_value": 0, + "mask_fill_value": null + }, + { + "__class_fullname__": "Downscale", + "always_apply": false, + "p": 0.5, + "scale_min": 0.25, + "scale_max": 0.25, + "interpolation": 0 + }, + { + "__class_fullname__": "ElasticTransform", + "always_apply": false, + "p": 0.5, + "alpha": 1, + "sigma": 50, + "alpha_affine": 50, + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null, + "approximate": false + }, + { + "__class_fullname__": "Equalize", + "always_apply": false, + "p": 0.5, + "mode": "cv", + "by_channels": true + }, + { + "__class_fullname__": "FancyPCA", + "always_apply": false, + "p": 0.5, + "alpha": 0.1 + }, + { + "__class_fullname__": "Flip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "GaussNoise", + "always_apply": false, + "p": 0.5, + "var_limit": [ + 10.0, + 50.0 + ], + "per_channel": true, + "mean": 0 + }, + { + "__class_fullname__": "GaussianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ], + "sigma_limit": [ + 0, + 0 + ] + }, + { + "__class_fullname__": "GlassBlur", + "always_apply": false, + "p": 0.5, + "sigma": 0.7, + "max_delta": 4, + "iterations": 2 + }, + { + "__class_fullname__": "GridDistortion", + "always_apply": false, + "p": 0.5, + "num_steps": 5, + "distort_limit": [ + -0.3, + 0.3 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "HorizontalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "HueSaturationValue", + "always_apply": false, + "p": 0.5, + "hue_shift_limit": [ + -20, + 20 + ], + "sat_shift_limit": [ + -30, + 30 + ], + "val_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "ISONoise", + "always_apply": false, + "p": 0.5, + "intensity": [ + 0.1, + 0.5 + ], + "color_shift": [ + 0.01, + 0.05 + ] + }, + { + "__class_fullname__": "ImageCompression", + "always_apply": false, + "p": 0.5, + "quality_lower": 99, + "quality_upper": 100, + "compression_type": 0 + }, + { + "__class_fullname__": "InvertImg", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "LongestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "MedianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "MotionBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "MultiplicativeNoise", + "always_apply": false, + "p": 0.5, + "multiplier": [ + 0.9, + 1.1 + ], + "per_channel": false, + "elementwise": false + }, + { + "__class_fullname__": "NoOp", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "OpticalDistortion", + "always_apply": false, + "p": 0.5, + "distort_limit": [ + -0.05, + 0.05 + ], + "shift_limit": [ + -0.05, + 0.05 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "PadIfNeeded", + "always_apply": false, + "p": 1.0, + "min_height": 1024, + "min_width": 1024, + "pad_height_divisor": null, + "pad_width_divisor": null, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "Posterize", + "always_apply": false, + "p": 0.5, + "num_bits": [ + 4, + 4 + ] + }, + { + "__class_fullname__": "RGBShift", + "always_apply": false, + "p": 0.5, + "r_shift_limit": [ + -20, + 20 + ], + "g_shift_limit": [ + -20, + 20 + ], + "b_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "RandomBrightnessContrast", + "always_apply": false, + "p": 0.5, + "brightness_limit": [ + -0.2, + 0.2 + ], + "contrast_limit": [ + -0.2, + 0.2 + ], + "brightness_by_max": true + }, + { + "__class_fullname__": "RandomFog", + "always_apply": false, + "p": 0.5, + "fog_coef_lower": 0.3, + "fog_coef_upper": 1, + "alpha_coef": 0.08 + }, + { + "__class_fullname__": "RandomGamma", + "always_apply": false, + "p": 0.5, + "gamma_limit": [ + 80, + 120 + ] + }, + { + "__class_fullname__": "RandomGridShuffle", + "always_apply": false, + "p": 0.5, + "grid": [ + 3, + 3 + ] + }, + { + "__class_fullname__": "RandomRain", + "always_apply": false, + "p": 0.5, + "slant_lower": -10, + "slant_upper": 10, + "drop_length": 20, + "drop_width": 1, + "drop_color": [ + 200, + 200, + 200 + ], + "blur_value": 7, + "brightness_coefficient": 0.7, + "rain_type": null + }, + { + "__class_fullname__": "RandomRotate90", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "RandomScale", + "always_apply": false, + "p": 0.5, + "interpolation": 1, + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ] + }, + { + "__class_fullname__": "RandomShadow", + "always_apply": false, + "p": 0.5, + "shadow_roi": [ + 0, + 0.5, + 1, + 1 + ], + "num_shadows_lower": 1, + "num_shadows_upper": 2, + "shadow_dimension": 5 + }, + { + "__class_fullname__": "RandomSnow", + "always_apply": false, + "p": 0.5, + "snow_point_lower": 0.1, + "snow_point_upper": 0.3, + "brightness_coeff": 2.5 + }, + { + "__class_fullname__": "RandomSunFlare", + "always_apply": false, + "p": 0.5, + "flare_roi": [ + 0, + 0, + 1, + 0.5 + ], + "angle_lower": 0, + "angle_upper": 1, + "num_flare_circles_lower": 6, + "num_flare_circles_upper": 10, + "src_radius": 400, + "src_color": [ + 255, + 255, + 255 + ] + }, + { + "__class_fullname__": "Rotate", + "always_apply": false, + "p": 0.5, + "limit": [ + -90, + 90 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "ShiftScaleRotate", + "always_apply": false, + "p": 0.5, + "shift_limit_x": [ + -0.0625, + 0.0625 + ], + "shift_limit_y": [ + -0.0625, + 0.0625 + ], + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ], + "rotate_limit": [ + -45, + 45 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "SmallestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "Solarize", + "always_apply": false, + "p": 0.5, + "threshold": [ + 128, + 128 + ] + }, + { + "__class_fullname__": "ToGray", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "ToSepia", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "Transpose", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "VerticalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "RandomCrop", + "always_apply": false, + "p": 1.0, + "height": 32, + "width": 32 + }, + { + "__class_fullname__": "Normalize", + "always_apply": false, + "p": 1.0, + "mean": [ + 0.485, + 0.456, + 0.406 + ], + "std": [ + 0.229, + 0.224, + 0.225 + ], + "max_pixel_value": 255.0 + } + ], + "bbox_params": null, + "keypoint_params": null, + "additional_targets": {} + } +} diff --git a/tests/files/transform_v1.1.0_with_totensor.json b/tests/files/transform_v1.1.0_with_totensor.json index e610700dd..23e55f27b 100644 --- a/tests/files/transform_v1.1.0_with_totensor.json +++ b/tests/files/transform_v1.1.0_with_totensor.json @@ -1 +1,494 @@ -{"__version__": "0.4.6", "transform": {"__class_fullname__": "albumentations.core.composition.Compose", "p": 1.0, "transforms": [{"__class_fullname__": "albumentations.augmentations.transforms.Blur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.CLAHE", "always_apply": false, "p": 0.5, "clip_limit": [1, 4.0], "tile_grid_size": [8, 8]}, {"__class_fullname__": "albumentations.augmentations.transforms.ChannelDropout", "always_apply": false, "p": 0.5, "channel_drop_range": [1, 1], "fill_value": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.ChannelShuffle", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.CoarseDropout", "always_apply": false, "p": 0.5, "max_holes": 8, "max_height": 8, "max_width": 8, "min_holes": 8, "min_height": 8, "min_width": 8}, {"__class_fullname__": "albumentations.augmentations.transforms.Downscale", "always_apply": false, "p": 0.5, "scale_min": 0.25, "scale_max": 0.25, "interpolation": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.ElasticTransform", "always_apply": false, "p": 0.5, "alpha": 1, "sigma": 50, "alpha_affine": 50, "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null, "approximate": false}, {"__class_fullname__": "albumentations.augmentations.transforms.Equalize", "always_apply": false, "p": 0.5, "mode": "cv", "by_channels": true}, {"__class_fullname__": "albumentations.augmentations.transforms.FancyPCA", "always_apply": false, "p": 0.5, "alpha": 0.1}, {"__class_fullname__": "albumentations.augmentations.transforms.Flip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.GaussNoise", "always_apply": false, "p": 0.5, "var_limit": [10.0, 50.0]}, {"__class_fullname__": "albumentations.augmentations.transforms.GaussianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.GlassBlur", "always_apply": false, "p": 0.5, "sigma": 0.7, "max_delta": 4, "iterations": 2}, {"__class_fullname__": "albumentations.augmentations.transforms.GridDistortion", "always_apply": false, "p": 0.5, "num_steps": 5, "distort_limit": [-0.3, 0.3], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.HorizontalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.HueSaturationValue", "always_apply": false, "p": 0.5, "hue_shift_limit": [-20, 20], "sat_shift_limit": [-30, 30], "val_shift_limit": [-20, 20]}, {"__class_fullname__": "albumentations.augmentations.transforms.ISONoise", "always_apply": false, "p": 0.5, "intensity": [0.1, 0.5], "color_shift": [0.01, 0.05]}, {"__class_fullname__": "albumentations.augmentations.transforms.ImageCompression", "always_apply": false, "p": 0.5, "quality_lower": 99, "quality_upper": 100, "compression_type": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.InvertImg", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.LongestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "albumentations.augmentations.transforms.MedianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.MotionBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.MultiplicativeNoise", "always_apply": false, "p": 0.5, "multiplier": [0.9, 1.1], "per_channel": false, "elementwise": false}, {"__class_fullname__": "albumentations.core.transforms_interface.NoOp", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.OpticalDistortion", "always_apply": false, "p": 0.5, "distort_limit": [-0.05, 0.05], "shift_limit": [-0.05, 0.05], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.PadIfNeeded", "always_apply": false, "p": 1.0, "min_height": 1024, "min_width": 1024, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.Posterize", "always_apply": false, "p": 0.5, "num_bits": [4, 4]}, {"__class_fullname__": "albumentations.augmentations.transforms.RGBShift", "always_apply": false, "p": 0.5, "r_shift_limit": [-20, 20], "g_shift_limit": [-20, 20], "b_shift_limit": [-20, 20]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomBrightnessContrast", "always_apply": false, "p": 0.5, "brightness_limit": [-0.2, 0.2], "contrast_limit": [-0.2, 0.2], "brightness_by_max": true}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomFog", "always_apply": false, "p": 0.5, "fog_coef_lower": 0.3, "fog_coef_upper": 1, "alpha_coef": 0.08}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomGamma", "always_apply": false, "p": 0.5, "gamma_limit": [80, 120], "eps": null}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomGridShuffle", "always_apply": false, "p": 0.5, "grid": [3, 3]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomRain", "always_apply": false, "p": 0.5, "slant_lower": -10, "slant_upper": 10, "drop_length": 20, "drop_width": 1, "drop_color": [200, 200, 200], "blur_value": 7, "brightness_coefficient": 0.7, "rain_type": null}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomRotate90", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomScale", "always_apply": false, "p": 0.5, "interpolation": 1, "scale_limit": [-0.09999999999999998, 0.10000000000000009]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomShadow", "always_apply": false, "p": 0.5, "shadow_roi": [0, 0.5, 1, 1], "num_shadows_lower": 1, "num_shadows_upper": 2, "shadow_dimension": 5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomSnow", "always_apply": false, "p": 0.5, "snow_point_lower": 0.1, "snow_point_upper": 0.3, "brightness_coeff": 2.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomSunFlare", "always_apply": false, "p": 0.5, "flare_roi": [0, 0, 1, 0.5], "angle_lower": 0, "angle_upper": 1, "num_flare_circles_lower": 6, "num_flare_circles_upper": 10, "src_radius": 400, "src_color": [255, 255, 255]}, {"__class_fullname__": "albumentations.augmentations.transforms.Rotate", "always_apply": false, "p": 0.5, "limit": [-90, 90], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.ShiftScaleRotate", "always_apply": false, "p": 0.5, "shift_limit": [-0.0625, 0.0625], "scale_limit": [-0.09999999999999998, 0.10000000000000009], "rotate_limit": [-45, 45], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.SmallestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "albumentations.augmentations.transforms.Solarize", "always_apply": false, "p": 0.5, "threshold": [128, 128]}, {"__class_fullname__": "albumentations.augmentations.transforms.ToGray", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.ToSepia", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.Transpose", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.VerticalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomCrop", "always_apply": false, "p": 1.0, "height": 32, "width": 32}, {"__class_fullname__": "albumentations.augmentations.transforms.Normalize", "always_apply": false, "p": 1.0, "mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225], "max_pixel_value": 255.0}, {"__class_fullname__": "albumentations.pytorch.transforms.ToTensorV2", "always_apply": true, "p": 1.0}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}}} +{ + "__version__": "0.4.6", + "transform": { + "__class_fullname__": "albumentations.core.composition.Compose", + "p": 1.0, + "transforms": [ + { + "__class_fullname__": "albumentations.augmentations.transforms.Blur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.CLAHE", + "always_apply": false, + "p": 0.5, + "clip_limit": [ + 1, + 4.0 + ], + "tile_grid_size": [ + 8, + 8 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ChannelDropout", + "always_apply": false, + "p": 0.5, + "channel_drop_range": [ + 1, + 1 + ], + "fill_value": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ChannelShuffle", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.CoarseDropout", + "always_apply": false, + "p": 0.5, + "max_holes": 8, + "max_height": 8, + "max_width": 8, + "min_holes": 8, + "min_height": 8, + "min_width": 8 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Downscale", + "always_apply": false, + "p": 0.5, + "scale_min": 0.25, + "scale_max": 0.25, + "interpolation": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ElasticTransform", + "always_apply": false, + "p": 0.5, + "alpha": 1, + "sigma": 50, + "alpha_affine": 50, + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null, + "approximate": false + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Equalize", + "always_apply": false, + "p": 0.5, + "mode": "cv", + "by_channels": true + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.FancyPCA", + "always_apply": false, + "p": 0.5, + "alpha": 0.1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Flip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GaussNoise", + "always_apply": false, + "p": 0.5, + "var_limit": [ + 10.0, + 50.0 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GaussianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GlassBlur", + "always_apply": false, + "p": 0.5, + "sigma": 0.7, + "max_delta": 4, + "iterations": 2 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GridDistortion", + "always_apply": false, + "p": 0.5, + "num_steps": 5, + "distort_limit": [ + -0.3, + 0.3 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.HorizontalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.HueSaturationValue", + "always_apply": false, + "p": 0.5, + "hue_shift_limit": [ + -20, + 20 + ], + "sat_shift_limit": [ + -30, + 30 + ], + "val_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ISONoise", + "always_apply": false, + "p": 0.5, + "intensity": [ + 0.1, + 0.5 + ], + "color_shift": [ + 0.01, + 0.05 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ImageCompression", + "always_apply": false, + "p": 0.5, + "quality_lower": 99, + "quality_upper": 100, + "compression_type": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.InvertImg", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.LongestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MedianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MotionBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MultiplicativeNoise", + "always_apply": false, + "p": 0.5, + "multiplier": [ + 0.9, + 1.1 + ], + "per_channel": false, + "elementwise": false + }, + { + "__class_fullname__": "albumentations.core.transforms_interface.NoOp", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.OpticalDistortion", + "always_apply": false, + "p": 0.5, + "distort_limit": [ + -0.05, + 0.05 + ], + "shift_limit": [ + -0.05, + 0.05 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.PadIfNeeded", + "always_apply": false, + "p": 1.0, + "min_height": 1024, + "min_width": 1024, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Posterize", + "always_apply": false, + "p": 0.5, + "num_bits": [ + 4, + 4 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RGBShift", + "always_apply": false, + "p": 0.5, + "r_shift_limit": [ + -20, + 20 + ], + "g_shift_limit": [ + -20, + 20 + ], + "b_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomBrightnessContrast", + "always_apply": false, + "p": 0.5, + "brightness_limit": [ + -0.2, + 0.2 + ], + "contrast_limit": [ + -0.2, + 0.2 + ], + "brightness_by_max": true + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomFog", + "always_apply": false, + "p": 0.5, + "fog_coef_lower": 0.3, + "fog_coef_upper": 1, + "alpha_coef": 0.08 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomGamma", + "always_apply": false, + "p": 0.5, + "gamma_limit": [ + 80, + 120 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomGridShuffle", + "always_apply": false, + "p": 0.5, + "grid": [ + 3, + 3 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomRain", + "always_apply": false, + "p": 0.5, + "slant_lower": -10, + "slant_upper": 10, + "drop_length": 20, + "drop_width": 1, + "drop_color": [ + 200, + 200, + 200 + ], + "blur_value": 7, + "brightness_coefficient": 0.7, + "rain_type": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomRotate90", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomScale", + "always_apply": false, + "p": 0.5, + "interpolation": 1, + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomShadow", + "always_apply": false, + "p": 0.5, + "shadow_roi": [ + 0, + 0.5, + 1, + 1 + ], + "num_shadows_lower": 1, + "num_shadows_upper": 2, + "shadow_dimension": 5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomSnow", + "always_apply": false, + "p": 0.5, + "snow_point_lower": 0.1, + "snow_point_upper": 0.3, + "brightness_coeff": 2.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomSunFlare", + "always_apply": false, + "p": 0.5, + "flare_roi": [ + 0, + 0, + 1, + 0.5 + ], + "angle_lower": 0, + "angle_upper": 1, + "num_flare_circles_lower": 6, + "num_flare_circles_upper": 10, + "src_radius": 400, + "src_color": [ + 255, + 255, + 255 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Rotate", + "always_apply": false, + "p": 0.5, + "limit": [ + -90, + 90 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ShiftScaleRotate", + "always_apply": false, + "p": 0.5, + "shift_limit": [ + -0.0625, + 0.0625 + ], + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ], + "rotate_limit": [ + -45, + 45 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.SmallestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Solarize", + "always_apply": false, + "p": 0.5, + "threshold": [ + 128, + 128 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ToGray", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ToSepia", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Transpose", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.VerticalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomCrop", + "always_apply": false, + "p": 1.0, + "height": 32, + "width": 32 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Normalize", + "always_apply": false, + "p": 1.0, + "mean": [ + 0.485, + 0.456, + 0.406 + ], + "std": [ + 0.229, + 0.224, + 0.225 + ], + "max_pixel_value": 255.0 + }, + { + "__class_fullname__": "albumentations.pytorch.transforms.ToTensorV2", + "always_apply": true, + "p": 1.0 + } + ], + "bbox_params": null, + "keypoint_params": null, + "additional_targets": {} + } +} diff --git a/tests/files/transform_v1.1.0_without_totensor.json b/tests/files/transform_v1.1.0_without_totensor.json index 8030f14b3..862b4fa10 100644 --- a/tests/files/transform_v1.1.0_without_totensor.json +++ b/tests/files/transform_v1.1.0_without_totensor.json @@ -1 +1,489 @@ -{"__version__": "0.4.6", "transform": {"__class_fullname__": "albumentations.core.composition.Compose", "p": 1.0, "transforms": [{"__class_fullname__": "albumentations.augmentations.transforms.Blur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.CLAHE", "always_apply": false, "p": 0.5, "clip_limit": [1, 4.0], "tile_grid_size": [8, 8]}, {"__class_fullname__": "albumentations.augmentations.transforms.ChannelDropout", "always_apply": false, "p": 0.5, "channel_drop_range": [1, 1], "fill_value": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.ChannelShuffle", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.CoarseDropout", "always_apply": false, "p": 0.5, "max_holes": 8, "max_height": 8, "max_width": 8, "min_holes": 8, "min_height": 8, "min_width": 8}, {"__class_fullname__": "albumentations.augmentations.transforms.Downscale", "always_apply": false, "p": 0.5, "scale_min": 0.25, "scale_max": 0.25, "interpolation": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.ElasticTransform", "always_apply": false, "p": 0.5, "alpha": 1, "sigma": 50, "alpha_affine": 50, "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null, "approximate": false}, {"__class_fullname__": "albumentations.augmentations.transforms.Equalize", "always_apply": false, "p": 0.5, "mode": "cv", "by_channels": true}, {"__class_fullname__": "albumentations.augmentations.transforms.FancyPCA", "always_apply": false, "p": 0.5, "alpha": 0.1}, {"__class_fullname__": "albumentations.augmentations.transforms.Flip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.GaussNoise", "always_apply": false, "p": 0.5, "var_limit": [10.0, 50.0]}, {"__class_fullname__": "albumentations.augmentations.transforms.GaussianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.GlassBlur", "always_apply": false, "p": 0.5, "sigma": 0.7, "max_delta": 4, "iterations": 2}, {"__class_fullname__": "albumentations.augmentations.transforms.GridDistortion", "always_apply": false, "p": 0.5, "num_steps": 5, "distort_limit": [-0.3, 0.3], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.HorizontalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.HueSaturationValue", "always_apply": false, "p": 0.5, "hue_shift_limit": [-20, 20], "sat_shift_limit": [-30, 30], "val_shift_limit": [-20, 20]}, {"__class_fullname__": "albumentations.augmentations.transforms.ISONoise", "always_apply": false, "p": 0.5, "intensity": [0.1, 0.5], "color_shift": [0.01, 0.05]}, {"__class_fullname__": "albumentations.augmentations.transforms.ImageCompression", "always_apply": false, "p": 0.5, "quality_lower": 99, "quality_upper": 100, "compression_type": 0}, {"__class_fullname__": "albumentations.augmentations.transforms.InvertImg", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.LongestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "albumentations.augmentations.transforms.MedianBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.MotionBlur", "always_apply": false, "p": 0.5, "blur_limit": [3, 7]}, {"__class_fullname__": "albumentations.augmentations.transforms.MultiplicativeNoise", "always_apply": false, "p": 0.5, "multiplier": [0.9, 1.1], "per_channel": false, "elementwise": false}, {"__class_fullname__": "albumentations.core.transforms_interface.NoOp", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.OpticalDistortion", "always_apply": false, "p": 0.5, "distort_limit": [-0.05, 0.05], "shift_limit": [-0.05, 0.05], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.PadIfNeeded", "always_apply": false, "p": 1.0, "min_height": 1024, "min_width": 1024, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.Posterize", "always_apply": false, "p": 0.5, "num_bits": [4, 4]}, {"__class_fullname__": "albumentations.augmentations.transforms.RGBShift", "always_apply": false, "p": 0.5, "r_shift_limit": [-20, 20], "g_shift_limit": [-20, 20], "b_shift_limit": [-20, 20]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomBrightnessContrast", "always_apply": false, "p": 0.5, "brightness_limit": [-0.2, 0.2], "contrast_limit": [-0.2, 0.2], "brightness_by_max": true}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomFog", "always_apply": false, "p": 0.5, "fog_coef_lower": 0.3, "fog_coef_upper": 1, "alpha_coef": 0.08}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomGamma", "always_apply": false, "p": 0.5, "gamma_limit": [80, 120], "eps": null}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomGridShuffle", "always_apply": false, "p": 0.5, "grid": [3, 3]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomRain", "always_apply": false, "p": 0.5, "slant_lower": -10, "slant_upper": 10, "drop_length": 20, "drop_width": 1, "drop_color": [200, 200, 200], "blur_value": 7, "brightness_coefficient": 0.7, "rain_type": null}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomRotate90", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomScale", "always_apply": false, "p": 0.5, "interpolation": 1, "scale_limit": [-0.09999999999999998, 0.10000000000000009]}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomShadow", "always_apply": false, "p": 0.5, "shadow_roi": [0, 0.5, 1, 1], "num_shadows_lower": 1, "num_shadows_upper": 2, "shadow_dimension": 5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomSnow", "always_apply": false, "p": 0.5, "snow_point_lower": 0.1, "snow_point_upper": 0.3, "brightness_coeff": 2.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomSunFlare", "always_apply": false, "p": 0.5, "flare_roi": [0, 0, 1, 0.5], "angle_lower": 0, "angle_upper": 1, "num_flare_circles_lower": 6, "num_flare_circles_upper": 10, "src_radius": 400, "src_color": [255, 255, 255]}, {"__class_fullname__": "albumentations.augmentations.transforms.Rotate", "always_apply": false, "p": 0.5, "limit": [-90, 90], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.ShiftScaleRotate", "always_apply": false, "p": 0.5, "shift_limit": [-0.0625, 0.0625], "scale_limit": [-0.09999999999999998, 0.10000000000000009], "rotate_limit": [-45, 45], "interpolation": 1, "border_mode": 4, "value": null, "mask_value": null}, {"__class_fullname__": "albumentations.augmentations.transforms.SmallestMaxSize", "always_apply": false, "p": 1, "max_size": 1024, "interpolation": 1}, {"__class_fullname__": "albumentations.augmentations.transforms.Solarize", "always_apply": false, "p": 0.5, "threshold": [128, 128]}, {"__class_fullname__": "albumentations.augmentations.transforms.ToGray", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.ToSepia", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.Transpose", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.VerticalFlip", "always_apply": false, "p": 0.5}, {"__class_fullname__": "albumentations.augmentations.transforms.RandomCrop", "always_apply": false, "p": 1.0, "height": 32, "width": 32}, {"__class_fullname__": "albumentations.augmentations.transforms.Normalize", "always_apply": false, "p": 1.0, "mean": [0.485, 0.456, 0.406], "std": [0.229, 0.224, 0.225], "max_pixel_value": 255.0}], "bbox_params": null, "keypoint_params": null, "additional_targets": {}}} +{ + "__version__": "0.4.6", + "transform": { + "__class_fullname__": "albumentations.core.composition.Compose", + "p": 1.0, + "transforms": [ + { + "__class_fullname__": "albumentations.augmentations.transforms.Blur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.CLAHE", + "always_apply": false, + "p": 0.5, + "clip_limit": [ + 1, + 4.0 + ], + "tile_grid_size": [ + 8, + 8 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ChannelDropout", + "always_apply": false, + "p": 0.5, + "channel_drop_range": [ + 1, + 1 + ], + "fill_value": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ChannelShuffle", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.CoarseDropout", + "always_apply": false, + "p": 0.5, + "max_holes": 8, + "max_height": 8, + "max_width": 8, + "min_holes": 8, + "min_height": 8, + "min_width": 8 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Downscale", + "always_apply": false, + "p": 0.5, + "scale_min": 0.25, + "scale_max": 0.25, + "interpolation": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ElasticTransform", + "always_apply": false, + "p": 0.5, + "alpha": 1, + "sigma": 50, + "alpha_affine": 50, + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null, + "approximate": false + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Equalize", + "always_apply": false, + "p": 0.5, + "mode": "cv", + "by_channels": true + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.FancyPCA", + "always_apply": false, + "p": 0.5, + "alpha": 0.1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Flip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GaussNoise", + "always_apply": false, + "p": 0.5, + "var_limit": [ + 10.0, + 50.0 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GaussianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GlassBlur", + "always_apply": false, + "p": 0.5, + "sigma": 0.7, + "max_delta": 4, + "iterations": 2 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.GridDistortion", + "always_apply": false, + "p": 0.5, + "num_steps": 5, + "distort_limit": [ + -0.3, + 0.3 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.HorizontalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.HueSaturationValue", + "always_apply": false, + "p": 0.5, + "hue_shift_limit": [ + -20, + 20 + ], + "sat_shift_limit": [ + -30, + 30 + ], + "val_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ISONoise", + "always_apply": false, + "p": 0.5, + "intensity": [ + 0.1, + 0.5 + ], + "color_shift": [ + 0.01, + 0.05 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ImageCompression", + "always_apply": false, + "p": 0.5, + "quality_lower": 99, + "quality_upper": 100, + "compression_type": 0 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.InvertImg", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.LongestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MedianBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MotionBlur", + "always_apply": false, + "p": 0.5, + "blur_limit": [ + 3, + 7 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.MultiplicativeNoise", + "always_apply": false, + "p": 0.5, + "multiplier": [ + 0.9, + 1.1 + ], + "per_channel": false, + "elementwise": false + }, + { + "__class_fullname__": "albumentations.core.transforms_interface.NoOp", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.OpticalDistortion", + "always_apply": false, + "p": 0.5, + "distort_limit": [ + -0.05, + 0.05 + ], + "shift_limit": [ + -0.05, + 0.05 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.PadIfNeeded", + "always_apply": false, + "p": 1.0, + "min_height": 1024, + "min_width": 1024, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Posterize", + "always_apply": false, + "p": 0.5, + "num_bits": [ + 4, + 4 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RGBShift", + "always_apply": false, + "p": 0.5, + "r_shift_limit": [ + -20, + 20 + ], + "g_shift_limit": [ + -20, + 20 + ], + "b_shift_limit": [ + -20, + 20 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomBrightnessContrast", + "always_apply": false, + "p": 0.5, + "brightness_limit": [ + -0.2, + 0.2 + ], + "contrast_limit": [ + -0.2, + 0.2 + ], + "brightness_by_max": true + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomFog", + "always_apply": false, + "p": 0.5, + "fog_coef_lower": 0.3, + "fog_coef_upper": 1, + "alpha_coef": 0.08 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomGamma", + "always_apply": false, + "p": 0.5, + "gamma_limit": [ + 80, + 120 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomGridShuffle", + "always_apply": false, + "p": 0.5, + "grid": [ + 3, + 3 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomRain", + "always_apply": false, + "p": 0.5, + "slant_lower": -10, + "slant_upper": 10, + "drop_length": 20, + "drop_width": 1, + "drop_color": [ + 200, + 200, + 200 + ], + "blur_value": 7, + "brightness_coefficient": 0.7, + "rain_type": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomRotate90", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomScale", + "always_apply": false, + "p": 0.5, + "interpolation": 1, + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomShadow", + "always_apply": false, + "p": 0.5, + "shadow_roi": [ + 0, + 0.5, + 1, + 1 + ], + "num_shadows_lower": 1, + "num_shadows_upper": 2, + "shadow_dimension": 5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomSnow", + "always_apply": false, + "p": 0.5, + "snow_point_lower": 0.1, + "snow_point_upper": 0.3, + "brightness_coeff": 2.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomSunFlare", + "always_apply": false, + "p": 0.5, + "flare_roi": [ + 0, + 0, + 1, + 0.5 + ], + "angle_lower": 0, + "angle_upper": 1, + "num_flare_circles_lower": 6, + "num_flare_circles_upper": 10, + "src_radius": 400, + "src_color": [ + 255, + 255, + 255 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Rotate", + "always_apply": false, + "p": 0.5, + "limit": [ + -90, + 90 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ShiftScaleRotate", + "always_apply": false, + "p": 0.5, + "shift_limit": [ + -0.0625, + 0.0625 + ], + "scale_limit": [ + -0.09999999999999998, + 0.10000000000000009 + ], + "rotate_limit": [ + -45, + 45 + ], + "interpolation": 1, + "border_mode": 4, + "value": null, + "mask_value": null + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.SmallestMaxSize", + "always_apply": false, + "p": 1, + "max_size": 1024, + "interpolation": 1 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Solarize", + "always_apply": false, + "p": 0.5, + "threshold": [ + 128, + 128 + ] + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ToGray", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.ToSepia", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Transpose", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.VerticalFlip", + "always_apply": false, + "p": 0.5 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.RandomCrop", + "always_apply": false, + "p": 1.0, + "height": 32, + "width": 32 + }, + { + "__class_fullname__": "albumentations.augmentations.transforms.Normalize", + "always_apply": false, + "p": 1.0, + "mean": [ + 0.485, + 0.456, + 0.406 + ], + "std": [ + 0.229, + 0.224, + 0.225 + ], + "max_pixel_value": 255.0 + } + ], + "bbox_params": null, + "keypoint_params": null, + "additional_targets": {} + } +} diff --git a/tests/test_imgaug.py b/tests/test_imgaug.py deleted file mode 100644 index 515b4ddae..000000000 --- a/tests/test_imgaug.py +++ /dev/null @@ -1,305 +0,0 @@ -import cv2 -import imgaug as ia -import numpy as np -import pytest - -import albumentations as A -from albumentations import Compose -from albumentations.core.bbox_utils import ( - convert_bboxes_from_albumentations, - convert_bboxes_to_albumentations, -) -from albumentations.imgaug.transforms import ( - IAAAdditiveGaussianNoise, - IAAAffine, - IAACropAndPad, - IAAFliplr, - IAAFlipud, - IAAPerspective, - IAAPiecewiseAffine, - IAASharpen, - IAASuperpixels, -) -from tests.utils import set_seed - -TEST_SEEDS = (0, 1, 42, 111, 9999) - - -@pytest.mark.parametrize("augmentation_cls", [IAASuperpixels, IAASharpen, IAAAdditiveGaussianNoise]) -def test_imgaug_image_only_augmentations(augmentation_cls, image, mask): - aug = augmentation_cls(p=1) - data = aug(image=image, mask=mask) - assert data["image"].dtype == np.uint8 - assert data["mask"].dtype == np.uint8 - assert np.array_equal(data["mask"], mask) - - -@pytest.mark.parametrize("augmentation_cls", [IAAPiecewiseAffine, IAAPerspective]) -def test_imgaug_dual_augmentations(augmentation_cls, image, mask): - aug = augmentation_cls(p=1) - data = aug(image=image, mask=mask) - assert data["image"].dtype == np.uint8 - assert data["mask"].dtype == np.uint8 - - -@pytest.mark.parametrize("augmentation_cls", [IAAPiecewiseAffine, IAAFliplr]) -def test_imagaug_dual_augmentations_are_deterministic(augmentation_cls, image): - aug = augmentation_cls(p=1) - mask = np.copy(image) - for _i in range(10): - data = aug(image=image, mask=mask) - assert np.array_equal(data["image"], data["mask"]) - - -def test_imagaug_fliplr_transform_bboxes(image): - aug = IAAFliplr(p=1) - mask = np.copy(image) - bboxes = [(10, 10, 20, 20), (20, 10, 30, 40)] - expect = [(80, 10, 90, 20), (70, 10, 80, 40)] - bboxes = convert_bboxes_to_albumentations(bboxes, "pascal_voc", rows=image.shape[0], cols=image.shape[1]) - data = aug(image=image, mask=mask, bboxes=bboxes) - actual = convert_bboxes_from_albumentations(data["bboxes"], "pascal_voc", rows=image.shape[0], cols=image.shape[1]) - assert np.array_equal(data["image"], data["mask"]) - assert np.allclose(actual, expect) - - -def test_imagaug_flipud_transform_bboxes(image): - aug = IAAFlipud(p=1) - mask = np.copy(image) - dummy_class = 1234 - bboxes = [(10, 10, 20, 20, dummy_class), (20, 10, 30, 40, dummy_class)] - expect = [(10, 80, 20, 90, dummy_class), (20, 60, 30, 90, dummy_class)] - bboxes = convert_bboxes_to_albumentations(bboxes, "pascal_voc", rows=image.shape[0], cols=image.shape[1]) - data = aug(image=image, mask=mask, bboxes=bboxes) - actual = convert_bboxes_from_albumentations(data["bboxes"], "pascal_voc", rows=image.shape[0], cols=image.shape[1]) - assert np.array_equal(data["image"], data["mask"]) - assert np.allclose(actual, expect) - - -@pytest.mark.parametrize( - ["aug", "keypoints", "expected"], - [ - [IAAFliplr, [(20, 30, 0, 0)], [(80, 30, 0, 0)]], - [IAAFliplr, [(20, 30, 45, 0)], [(80, 30, 45, 0)]], - [IAAFliplr, [(20, 30, 90, 0)], [(80, 30, 90, 0)]], - # - [IAAFlipud, [(20, 30, 0, 0)], [(20, 70, 0, 0)]], - [IAAFlipud, [(20, 30, 45, 0)], [(20, 70, 45, 0)]], - [IAAFlipud, [(20, 30, 90, 0)], [(20, 70, 90, 0)]], - ], -) -def test_keypoint_transform_format_xy(aug, keypoints, expected): - transform = Compose([aug(p=1)], keypoint_params={"format": "xy", "label_fields": ["labels"]}) - - image = np.ones((100, 100, 3)) - transformed = transform(image=image, keypoints=keypoints, labels=np.ones(len(keypoints))) - assert np.allclose(expected, transformed["keypoints"]) - - -@pytest.mark.parametrize(["aug", "keypoints", "expected"], [[IAAFliplr, [[20, 30, 0, 0]], [[79, 30, 0, 0]]]]) -def test_iaa_transforms_emit_warning(aug, keypoints, expected): - with pytest.warns(UserWarning, match="IAAFliplr transformation supports only 'xy' keypoints augmentation"): - Compose([aug(p=1)], keypoint_params={"format": "xyas", "label_fields": ["labels"]}) - - -@pytest.mark.parametrize( - ["augmentation_cls", "params"], - [ - [A.IAASuperpixels, {}], - [A.IAAAdditiveGaussianNoise, {}], - [A.IAACropAndPad, {}], - [A.IAAFliplr, {}], - [A.IAAFlipud, {}], - [A.IAAAffine, {}], - [A.IAAPiecewiseAffine, {}], - [A.IAAPerspective, {}], - ], -) -@pytest.mark.parametrize("p", [0.5, 1]) -@pytest.mark.parametrize("seed", TEST_SEEDS) -@pytest.mark.parametrize("always_apply", (False, True)) -def test_imgaug_augmentations_serialization(augmentation_cls, params, p, seed, image, mask, always_apply): - aug = augmentation_cls(p=p, always_apply=always_apply, **params) - serialized_aug = A.to_dict(aug) - deserialized_aug = A.from_dict(serialized_aug) - set_seed(seed) - ia.seed(seed) - aug_data = aug(image=image, mask=mask) - set_seed(seed) - ia.seed(seed) - deserialized_aug_data = deserialized_aug(image=image, mask=mask) - assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) - assert np.array_equal(aug_data["mask"], deserialized_aug_data["mask"]) - - -@pytest.mark.parametrize( - ["augmentation_cls", "params"], - [ - [A.IAASuperpixels, {}], - [A.IAAAdditiveGaussianNoise, {}], - [A.IAACropAndPad, {}], - [A.IAAFliplr, {}], - [A.IAAFlipud, {}], - [A.IAAAffine, {}], - [A.IAAPiecewiseAffine, {}], - [A.IAAPerspective, {}], - ], -) -@pytest.mark.parametrize("p", [0.5, 1]) -@pytest.mark.parametrize("seed", TEST_SEEDS) -@pytest.mark.parametrize("always_apply", (False, True)) -def test_imgaug_augmentations_for_bboxes_serialization( - augmentation_cls, params, p, seed, image, albumentations_bboxes, always_apply -): - aug = augmentation_cls(p=p, always_apply=always_apply, **params) - serialized_aug = A.to_dict(aug) - deserialized_aug = A.from_dict(serialized_aug) - set_seed(seed) - ia.seed(seed) - aug_data = aug(image=image, bboxes=albumentations_bboxes) - set_seed(seed) - ia.seed(seed) - deserialized_aug_data = deserialized_aug(image=image, bboxes=albumentations_bboxes) - assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) - assert np.array_equal(aug_data["bboxes"], deserialized_aug_data["bboxes"]) - - -@pytest.mark.parametrize( - ["augmentation_cls", "params"], - [ - [A.IAASuperpixels, {}], - [A.IAAAdditiveGaussianNoise, {}], - [A.IAACropAndPad, {}], - [A.IAAFliplr, {}], - [A.IAAFlipud, {}], - [A.IAAAffine, {}], - [A.IAAPiecewiseAffine, {}], - [A.IAAPerspective, {}], - ], -) -@pytest.mark.parametrize("p", [0.5, 1]) -@pytest.mark.parametrize("seed", TEST_SEEDS) -@pytest.mark.parametrize("always_apply", (False, True)) -def test_imgaug_augmentations_for_keypoints_serialization( - augmentation_cls, params, p, seed, image, keypoints, always_apply -): - aug = augmentation_cls(p=p, always_apply=always_apply, **params) - serialized_aug = A.to_dict(aug) - deserialized_aug = A.from_dict(serialized_aug) - set_seed(seed) - ia.seed(seed) - aug_data = aug(image=image, keypoints=keypoints) - set_seed(seed) - ia.seed(seed) - deserialized_aug_data = deserialized_aug(image=image, keypoints=keypoints) - assert np.array_equal(aug_data["image"], deserialized_aug_data["image"]) - assert np.array_equal(aug_data["keypoints"], deserialized_aug_data["keypoints"]) - - -@pytest.mark.parametrize( - ["augmentation_cls", "params"], - [ - [IAAAffine, {"scale": 1.5}], - [IAAPiecewiseAffine, {"scale": 1.5}], - [IAAPerspective, {}], - ], -) -def test_imgaug_transforms_binary_mask_interpolation(augmentation_cls, params): - """Checks whether transformations based on DualTransform does not introduce a mask interpolation artifacts""" - aug = augmentation_cls(p=1, **params) - image = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8) - mask = np.random.randint(low=0, high=2, size=(100, 100), dtype=np.uint8) - data = aug(image=image, mask=mask) - assert np.array_equal(np.unique(data["mask"]), np.array([0, 1])) - - -def __test_multiprocessing_support_proc(args): - x, transform = args - return transform(image=x) - - -@pytest.mark.parametrize( - ["augmentation_cls", "params"], - [ - [IAAAffine, {"scale": 1.5}], - [IAAPiecewiseAffine, {"scale": 1.5}], - [IAAPerspective, {}], - ], -) -def test_imgaug_transforms_multiprocessing_support(augmentation_cls, params, mp_pool): - """Checks whether we can use augmentations in multiprocessing environments""" - aug = augmentation_cls(p=1, **params) - image = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8) - - mp_pool.map(__test_multiprocessing_support_proc, map(lambda x: (x, aug), [image] * 100)) - - -@pytest.mark.parametrize( - ["img_dtype", "px", "percent", "pad_mode", "pad_cval"], - [ - [np.uint8, 10, None, cv2.BORDER_CONSTANT, 0], - [np.uint8, -10, None, cv2.BORDER_CONSTANT, 0], - [np.uint8, None, 0.1, cv2.BORDER_CONSTANT, 0], - [np.uint8, None, -0.1, cv2.BORDER_CONSTANT, 0], - ], -) -def test_compare_crop_and_pad(img_dtype, px, percent, pad_mode, pad_cval): - h, w, c = 100, 100, 3 - mode_mapping = { - cv2.BORDER_CONSTANT: "constant", - cv2.BORDER_REPLICATE: "edge", - cv2.BORDER_REFLECT101: "reflect", - cv2.BORDER_WRAP: "wrap", - } - pad_mode_iaa = mode_mapping[pad_mode] - - bbox_params = A.BboxParams(format="pascal_voc") - keypoint_params = A.KeypointParams(format="xy", remove_invisible=False) - - keypoints = np.random.randint(0, min(h, w), [10, 2]) - - bboxes = [] - for i in range(10): - x1, y1 = np.random.randint(0, min(h, w) - 2, 2) - x2 = np.random.randint(x1 + 1, w - 1) - y2 = np.random.randint(y1 + 1, h - 1) - bboxes.append([x1, y1, x2, y2, 0]) - - transform_albu = A.Compose( - [ - A.CropAndPad( - px=px, - percent=percent, - pad_mode=pad_mode, - pad_cval=pad_cval, - keep_size=True, - p=1, - interpolation=cv2.INTER_AREA - if (px is not None and px < 0) or (percent is not None and percent < 0) - else cv2.INTER_LINEAR, - ) - ], - bbox_params=bbox_params, - keypoint_params=keypoint_params, - ) - transform_iaa = A.Compose( - [IAACropAndPad(px=px, percent=percent, pad_mode=pad_mode_iaa, pad_cval=pad_cval, keep_size=True, p=1)], - bbox_params=bbox_params, - keypoint_params=keypoint_params, - ) - - if img_dtype == np.uint8: - img = np.random.randint(0, 256, (h, w, c), dtype=np.uint8) - else: - img = np.random.random((h, w, c)).astype(img_dtype) - - res_albu = transform_albu(image=img, keypoints=keypoints, bboxes=bboxes) - res_iaa = transform_iaa(image=img, keypoints=keypoints, bboxes=bboxes) - - for key, item in res_albu.items(): - if key == "bboxes": - bboxes = np.array(res_iaa[key]) - h = bboxes[:, 3] - bboxes[:, 1] - w = bboxes[:, 2] - bboxes[:, 0] - res_iaa[key] = bboxes[(h > 0) & (w > 0)] - assert np.allclose(item, res_iaa[key]), f"{key} are not equal" diff --git a/tests/test_imgaug_imports.py b/tests/test_imgaug_imports.py deleted file mode 100644 index bc159f997..000000000 --- a/tests/test_imgaug_imports.py +++ /dev/null @@ -1,82 +0,0 @@ -import pytest - -import albumentations as A -from albumentations.imgaug.stubs import IAAStub -from tests.conftest import skipif_no_imgaug, skipif_imgaug - - -@skipif_no_imgaug -@pytest.mark.parametrize( - "aug_name", - [ - "IAAEmboss", - "IAASuperpixels", - "IAASharpen", - "IAAAdditiveGaussianNoise", - "IAACropAndPad", - "IAAFliplr", - "IAAFlipud", - "IAAAffine", - "IAAPiecewiseAffine", - ], -) -def test_imgaug_augmentations_imported_when_imgaug_is_installed(aug_name): - aug_cls = getattr(A, aug_name) - t = aug_cls() - assert isinstance(t, A.BasicIAATransform) - - -@skipif_no_imgaug -def test_iaaperpective_augmentation_imported_when_imgaug_is_installed(): - from albumentations.imgaug.transforms import IAAPerspective - - t = IAAPerspective() - assert isinstance(t, A.DualTransform) - - -@skipif_imgaug -@pytest.mark.parametrize( - "aug_name", - [ - "IAAEmboss", - "IAASuperpixels", - "IAASharpen", - "IAAAdditiveGaussianNoise", - "IAACropAndPad", - "IAAFliplr", - "IAAFlipud", - "IAAAffine", - "IAAPiecewiseAffine", - "IAAPerspective", - ], -) -def test_imgaug_stubs_imported_when_imgaug_is_not_installed(aug_name): - aug_cls = getattr(A, aug_name) - assert issubclass(aug_cls, IAAStub) - with pytest.raises(RuntimeError) as exc_info: - aug_cls() - message = ( - f"You are trying to use a deprecated augmentation '{aug_name}' which depends on the imgaug library, " - f"but imgaug is not installed." - ) - assert message in str(exc_info.value) - - -@skipif_no_imgaug -def test_imports_from_imgaug_module_dont_raise_import_error(): - from albumentations.imgaug.transforms import IAAFlipud - - IAAFlipud() - - -@skipif_imgaug -def test_imports_from_imgaug_module_raise_import_error(): - with pytest.raises(ImportError) as exc_info: - from albumentations.imgaug.transforms import IAAFlipud - - message = ( - "You are trying to import an augmentation that depends on the imgaug library, but imgaug is not " - "installed. To install a version of Albumentations that contains imgaug please run " - "'pip install -U albumentations[imgaug]'" - ) - assert message in str(exc_info.value) diff --git a/tests/test_pytorch.py b/tests/test_pytorch.py index 52b0bf251..94ffe20f7 100644 --- a/tests/test_pytorch.py +++ b/tests/test_pytorch.py @@ -1,12 +1,11 @@ -import pytest - import numpy as np +import pytest import torch from PIL import Image from torchvision.transforms import ColorJitter import albumentations as A -from albumentations.pytorch.transforms import ToTensor, ToTensorV2 +from albumentations.pytorch.transforms import ToTensorV2 def test_torch_to_tensor_v2_augmentations(image, mask): @@ -91,18 +90,6 @@ def test_torch_to_tensor_v2_on_gray_scale_images(): assert data["image"].dtype == torch.uint8 -def test_torch_to_tensor_raises_runtime_error(): - with pytest.raises(RuntimeError) as exc_info: - aug = ToTensor() # noqa F841 - message = ( - "`ToTensor` is obsolete and it was removed from Albumentations. Please use `ToTensorV2` instead - " - "https://albumentations.ai/docs/api_reference/pytorch/transforms/" - "#albumentations.pytorch.transforms.ToTensorV2. " - "\n\nIf you need `ToTensor` downgrade Albumentations to version 0.5.2." - ) - assert str(exc_info.value) == message - - def test_with_replaycompose(): aug = A.ReplayCompose([ToTensorV2()]) kwargs = { @@ -159,7 +146,7 @@ def test_color_jitter(brightness, contrast, saturation, hue): res2 = np.array(pil_transform(pil_image)) _max = np.abs(res1.astype(np.int16) - res2.astype(np.int16)).max() - assert _max <= 2, "Max: {}".format(_max) + assert _max <= 2, f"Max: {_max}" def test_post_data_check(): diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 01cfcadf2..aca08f2a4 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -1,5 +1,4 @@ import io -import random from pathlib import Path from unittest.mock import patch @@ -74,7 +73,6 @@ def test_augmentations_serialization(augmentation_cls, params, p, seed, image, m "compression_type": A.ImageCompression.ImageCompressionType.WEBP, }, ], - [A.JpegCompression, {"quality_lower": 10, "quality_upper": 80}], [ A.HueSaturationValue, {"hue_shift_limit": 70, "sat_shift_limit": 95, "val_shift_limit": 55}, @@ -88,7 +86,6 @@ def test_augmentations_serialization(augmentation_cls, params, p, seed, image, m [A.GaussNoise, {"var_limit": (20, 90), "mean": 10, "per_channel": False}], [A.CLAHE, {"clip_limit": 2, "tile_grid_size": (12, 12)}], [A.RandomGamma, {"gamma_limit": (10, 90)}], - [A.Cutout, {"num_holes": 4, "max_h_size": 4, "max_w_size": 4}], [A.CoarseDropout, {"max_holes": 4, "max_height": 4, "max_width": 4}], [ A.RandomSnow, @@ -232,8 +229,6 @@ def test_augmentations_serialization(augmentation_cls, params, p, seed, image, m "max_pixel_value": 100.0, }, ], - [A.RandomBrightness, {"limit": 0.4}], - [A.RandomContrast, {"limit": 0.4}], [A.RandomScale, {"scale_limit": 0.2, "interpolation": cv2.INTER_CUBIC}], [A.Resize, {"height": 64, "width": 64}], [A.SmallestMaxSize, {"max_size": 64, "interpolation": cv2.INTER_CUBIC}], @@ -797,7 +792,7 @@ def vflip_keypoint(keypoint, **kwargs): ) serialized_aug = A.to_dict(aug) - deserialized_aug = A.from_dict(serialized_aug, lambda_transforms={"vflip": aug}) + deserialized_aug = A.from_dict(serialized_aug, nonserializable={"vflip": aug}) set_seed(seed) aug_data = aug(image=image, mask=mask, bboxes=albumentations_bboxes, keypoints=keypoints) set_seed(seed) @@ -904,7 +899,7 @@ def test_template_transform_serialization(image, template, seed, p): aug = A.Compose([A.Flip(), template_transform, A.Blur()]) serialized_aug = A.to_dict(aug) - deserialized_aug = A.from_dict(serialized_aug, lambda_transforms={"template": template_transform}) + deserialized_aug = A.from_dict(serialized_aug, nonserializable={"template": template_transform}) set_seed(seed) aug_data = aug(image=image) diff --git a/tools/make_transforms_docs.py b/tools/make_transforms_docs.py index 828a764b2..cb7475216 100644 --- a/tools/make_transforms_docs.py +++ b/tools/make_transforms_docs.py @@ -1,17 +1,14 @@ +import argparse import inspect import os import sys from enum import Enum -import argparse sys.path.append("..") import albumentations # noqa: E402 - IGNORED_CLASSES = { "BasicTransform", - "BasicIAATransform", - "DualIAATransform", "DualTransform", "ImageOnlyIAATransform", "ImageOnlyTransform", @@ -77,9 +74,6 @@ def get_transforms_info(): ): targets.add(Targets.KEYPOINTS) - if issubclass(cls, albumentations.DualIAATransform): - targets.update({Targets.BBOXES, Targets.KEYPOINTS}) - if issubclass(cls, albumentations.Lambda): targets.add(Targets.MASKS) targets.add(Targets.BBOXES) @@ -118,7 +112,7 @@ def make_transforms_targets_table(transforms_info, header): "{column: <{width}}".format(width=width, column=column) for width, column in zip(column_widths, row) ) ) - return "\n".join("| {line} |".format(line=line) for line in lines) + return "\n".join(f"| {line} |" for line in lines) def make_transforms_targets_links(transforms_info): @@ -128,7 +122,7 @@ def make_transforms_targets_links(transforms_info): def check_docs(filepath, image_only_transforms_links, dual_transforms_table): - with open(filepath, "r", encoding="utf8") as f: + with open(filepath, encoding="utf8") as f: text = f.read() outdated_docs = set() image_only_lines_not_in_text = [] @@ -168,9 +162,7 @@ def main(): args = parse_args() command = args.command if command not in {"make", "check"}: - raise ValueError( - "You should provide a valid command: {{make|check}}. Got {command} instead.".format(command=command) - ) + raise ValueError(f"You should provide a valid command: {{make|check}}. Got {command} instead.") transforms_info = get_transforms_info() image_only_transforms = {transform: info for transform, info in transforms_info.items() if info["image_only"]} dual_transforms = {transform: info for transform, info in transforms_info.items() if not info["image_only"]}