Skip to content

Commit

Permalink
Remove deprecated (#1520)
Browse files Browse the repository at this point in the history
* removed deprecated

* fixes for tests

* Updated setup.py

* Added docstring to ToTensorV2

* Updated tool that updates readme

* Updated readme
  • Loading branch information
ternaus committed Feb 16, 2024
1 parent 7eb5b34 commit be6a217
Show file tree
Hide file tree
Showing 26 changed files with 2,045 additions and 1,308 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -2,8 +2,10 @@ name: CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- main

jobs:
test_and_lint:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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 |
Expand Down Expand Up @@ -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

<img src="https://habrastorage.org/webt/e-/6k/z-/e-6kz-fugp2heak3jzns3bc-r8o.jpeg" width=100%>


## 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.
Expand Down
7 changes: 0 additions & 7 deletions albumentations/__init__.py
Expand Up @@ -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
1 change: 0 additions & 1 deletion albumentations/augmentations/__init__.py
Expand Up @@ -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 *
Expand Down
1 change: 0 additions & 1 deletion 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 *
85 changes: 0 additions & 85 deletions albumentations/augmentations/dropout/cutout.py

This file was deleted.

4 changes: 2 additions & 2 deletions 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
Expand Down
114 changes: 16 additions & 98 deletions albumentations/augmentations/transforms.py
Expand Up @@ -42,16 +42,13 @@
"RandomGridShuffle",
"HueSaturationValue",
"RGBShift",
"RandomBrightness",
"RandomContrast",
"GaussNoise",
"CLAHE",
"ChannelShuffle",
"InvertImg",
"ToGray",
"ToRGB",
"ToSepia",
"JpegCompression",
"ImageCompression",
"ToFloat",
"FromFloat",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -1545,22 +1465,20 @@ 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)

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):
Expand Down
21 changes: 0 additions & 21 deletions albumentations/core/keypoints_utils.py
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions albumentations/core/serialization.py
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Empty file removed albumentations/imgaug/__init__.py
Empty file.

0 comments on commit be6a217

Please sign in to comment.