diff --git a/albumentations/augmentations/__init__.py b/albumentations/augmentations/__init__.py index ce14821ee..73dd5e976 100644 --- a/albumentations/augmentations/__init__.py +++ b/albumentations/augmentations/__init__.py @@ -19,6 +19,5 @@ from .mixing.transforms import * from .text.functional import * from .text.transforms import * - from .transforms import * from .utils import * diff --git a/albumentations/augmentations/blur/transforms.py b/albumentations/augmentations/blur/transforms.py index fa21e9114..3097e0d37 100644 --- a/albumentations/augmentations/blur/transforms.py +++ b/albumentations/augmentations/blur/transforms.py @@ -2,7 +2,7 @@ import random import warnings -from typing import Any, Literal, cast, Tuple +from typing import Any, Literal, Tuple, cast import cv2 import numpy as np diff --git a/albumentations/augmentations/crops/functional.py b/albumentations/augmentations/crops/functional.py index 87b91dba5..d6bbeb8c5 100644 --- a/albumentations/augmentations/crops/functional.py +++ b/albumentations/augmentations/crops/functional.py @@ -3,15 +3,13 @@ from typing import Sequence, cast import cv2 +import numpy as np from albucore.utils import maybe_process_in_chunks, preserve_channel_dim from albumentations.augmentations.geometric import functional as fgeometric from albumentations.core.bbox_utils import denormalize_bbox, normalize_bbox from albumentations.core.types import BoxInternalType, ColorType, KeypointInternalType - -import numpy as np - __all__ = [ "get_crop_coords", "crop_bbox_by_coords", diff --git a/albumentations/augmentations/crops/transforms.py b/albumentations/augmentations/crops/transforms.py index 23706f92f..0a8394895 100644 --- a/albumentations/augmentations/crops/transforms.py +++ b/albumentations/augmentations/crops/transforms.py @@ -10,7 +10,6 @@ from pydantic import AfterValidator, Field, field_validator, model_validator from typing_extensions import Annotated, Self - from albumentations.augmentations.geometric import functional as fgeometric from albumentations.core.bbox_utils import union_of_bboxes from albumentations.core.pydantic import ( diff --git a/albumentations/augmentations/domain_adaptation.py b/albumentations/augmentations/domain_adaptation.py index 672d51809..258fde461 100644 --- a/albumentations/augmentations/domain_adaptation.py +++ b/albumentations/augmentations/domain_adaptation.py @@ -2,27 +2,24 @@ import random from typing import Any, Callable, Literal, Sequence, Tuple, cast -from typing_extensions import Annotated import cv2 import numpy as np from albucore.utils import clip, is_grayscale_image, is_multispectral_image from pydantic import AfterValidator, field_validator +from typing_extensions import Annotated +from albumentations.augmentations import functional as fmain from albumentations.augmentations.domain_adaptation_functional import ( adapt_pixel_distribution, apply_histogram, fourier_domain_adaptation, ) from albumentations.augmentations.utils import read_rgb_image -from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform -from albumentations.augmentations import functional as fmain - - from albumentations.core.pydantic import NonNegativeFloatRangeType, check_01, nondecreasing +from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform from albumentations.core.types import ScaleFloatType - __all__ = [ "HistogramMatching", "FDA", diff --git a/albumentations/augmentations/domain_adaptation_functional.py b/albumentations/augmentations/domain_adaptation_functional.py index e0426cbbc..4ba5e1f24 100644 --- a/albumentations/augmentations/domain_adaptation_functional.py +++ b/albumentations/augmentations/domain_adaptation_functional.py @@ -10,9 +10,9 @@ from skimage.exposure import match_histograms from typing_extensions import Protocol +import albumentations.augmentations.functional as fmain from albumentations.augmentations.functional import center from albumentations.core.types import MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS -import albumentations.augmentations.functional as fmain __all__ = [ "fourier_domain_adaptation", diff --git a/albumentations/augmentations/dropout/channel_dropout.py b/albumentations/augmentations/dropout/channel_dropout.py index 8464bd964..b0f8858d4 100644 --- a/albumentations/augmentations/dropout/channel_dropout.py +++ b/albumentations/augmentations/dropout/channel_dropout.py @@ -3,20 +3,17 @@ import random from typing import Any, Mapping -from typing_extensions import Annotated - -from albucore import get_num_channels -from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform - -from .functional import channel_dropout - - import numpy as np +from albucore import get_num_channels from pydantic import Field +from typing_extensions import Annotated from albumentations.core.pydantic import OnePlusIntRangeType +from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform from albumentations.core.types import ColorType +from .functional import channel_dropout + __all__ = ["ChannelDropout"] MIN_DROPOUT_CHANNEL_LIST_LENGTH = 2 diff --git a/albumentations/augmentations/dropout/coarse_dropout.py b/albumentations/augmentations/dropout/coarse_dropout.py index b84955df3..5df6ec537 100644 --- a/albumentations/augmentations/dropout/coarse_dropout.py +++ b/albumentations/augmentations/dropout/coarse_dropout.py @@ -3,20 +3,17 @@ from typing import Any, Callable, Iterable, Sequence from warnings import warn +import numpy as np from pydantic import AfterValidator, Field, model_validator from typing_extensions import Annotated, Literal, Self +from albumentations.core.pydantic import check_1plus, nondecreasing from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ColorType, KeypointType, NumericType, ScalarType, Targets from albumentations.random_utils import randint, uniform from .functional import cutout, keypoint_in_hole - -import numpy as np - -from albumentations.core.pydantic import check_1plus, nondecreasing - __all__ = ["CoarseDropout"] diff --git a/albumentations/augmentations/dropout/grid_dropout.py b/albumentations/augmentations/dropout/grid_dropout.py index 628c071d8..794eac4bb 100644 --- a/albumentations/augmentations/dropout/grid_dropout.py +++ b/albumentations/augmentations/dropout/grid_dropout.py @@ -4,19 +4,16 @@ from typing import Any, Iterable, Sequence from warnings import warn +import numpy as np from pydantic import AfterValidator, Field, model_validator from typing_extensions import Annotated, Self +from albumentations.core.pydantic import check_0plus, check_1plus, nondecreasing from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import MIN_UNIT_SIZE, PAIR, ColorType, Targets from . import functional as fdropout - -import numpy as np - -from albumentations.core.pydantic import check_0plus, check_1plus, nondecreasing - __all__ = ["GridDropout"] diff --git a/albumentations/augmentations/dropout/mask_dropout.py b/albumentations/augmentations/dropout/mask_dropout.py index edd53f786..0e55e0015 100644 --- a/albumentations/augmentations/dropout/mask_dropout.py +++ b/albumentations/augmentations/dropout/mask_dropout.py @@ -9,12 +9,10 @@ from skimage.measure import label from typing_extensions import Literal +from albumentations.core.pydantic import OnePlusIntRangeType from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ScalarType, ScaleIntType, Targets - -from albumentations.core.pydantic import OnePlusIntRangeType - __all__ = ["MaskDropout"] diff --git a/albumentations/augmentations/dropout/xy_masking.py b/albumentations/augmentations/dropout/xy_masking.py index eee7e4516..54c463123 100644 --- a/albumentations/augmentations/dropout/xy_masking.py +++ b/albumentations/augmentations/dropout/xy_masking.py @@ -3,19 +3,16 @@ import random from typing import Any, Callable, Sequence, Tuple, cast +import numpy as np from pydantic import Field, model_validator from typing_extensions import Self +from albumentations.core.pydantic import NonNegativeIntRangeType from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ColorType, KeypointType, ScaleIntType, Targets from .functional import cutout, keypoint_in_hole - -import numpy as np - -from albumentations.core.pydantic import NonNegativeIntRangeType - __all__ = ["XYMasking"] diff --git a/albumentations/augmentations/functional.py b/albumentations/augmentations/functional.py index b5dbb7baf..d1f1ab9f8 100644 --- a/albumentations/augmentations/functional.py +++ b/albumentations/augmentations/functional.py @@ -12,11 +12,11 @@ MAX_VALUES_BY_DTYPE, clip, clipped, + get_num_channels, is_grayscale_image, is_rgb_image, maybe_process_in_chunks, preserve_channel_dim, - get_num_channels, ) from typing_extensions import Literal diff --git a/albumentations/augmentations/geometric/functional.py b/albumentations/augmentations/geometric/functional.py index 612acd06b..f2e6617bf 100644 --- a/albumentations/augmentations/geometric/functional.py +++ b/albumentations/augmentations/geometric/functional.py @@ -6,7 +6,7 @@ import cv2 import numpy as np import skimage.transform -from albucore.utils import clipped, maybe_process_in_chunks, preserve_channel_dim, get_num_channels +from albucore.utils import clipped, get_num_channels, maybe_process_in_chunks, preserve_channel_dim from albumentations import random_utils from albumentations.augmentations.functional import center diff --git a/albumentations/augmentations/geometric/resize.py b/albumentations/augmentations/geometric/resize.py index 70a28b634..acc21b640 100644 --- a/albumentations/augmentations/geometric/resize.py +++ b/albumentations/augmentations/geometric/resize.py @@ -4,8 +4,10 @@ from typing import Any, List, Sequence, Tuple, Union, cast import cv2 +import numpy as np from pydantic import Field, ValidationInfo, field_validator +from albumentations.core.pydantic import InterpolationType, ProbabilityType from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ( BoxInternalType, @@ -17,11 +19,6 @@ from . import functional as fgeometric - -import numpy as np - -from albumentations.core.pydantic import InterpolationType, ProbabilityType - __all__ = ["RandomScale", "LongestMaxSize", "SmallestMaxSize", "Resize"] diff --git a/albumentations/augmentations/geometric/rotate.py b/albumentations/augmentations/geometric/rotate.py index 6e6a0c816..880299fcf 100644 --- a/albumentations/augmentations/geometric/rotate.py +++ b/albumentations/augmentations/geometric/rotate.py @@ -11,6 +11,7 @@ from albumentations.augmentations.crops import functional as fcrops from albumentations.augmentations.functional import center +from albumentations.core.pydantic import BorderModeType, InterpolationType, SymmetricRangeType from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ( BoxInternalType, @@ -22,9 +23,6 @@ from . import functional as fgeometric - -from albumentations.core.pydantic import BorderModeType, InterpolationType, SymmetricRangeType - __all__ = ["Rotate", "RandomRotate90", "SafeRotate"] SMALL_NUMBER = 1e-10 diff --git a/albumentations/augmentations/geometric/transforms.py b/albumentations/augmentations/geometric/transforms.py index e207aadec..2f209f753 100644 --- a/albumentations/augmentations/geometric/transforms.py +++ b/albumentations/augmentations/geometric/transforms.py @@ -17,6 +17,14 @@ from albumentations.augmentations.functional import bbox_from_mask, center, center_bbox from albumentations.augmentations.utils import check_range from albumentations.core.bbox_utils import denormalize_bboxes, normalize_bboxes +from albumentations.core.pydantic import ( + BorderModeType, + InterpolationType, + NonNegativeFloatRangeType, + ProbabilityType, + SymmetricRangeType, + check_1plus, +) from albumentations.core.transforms_interface import BaseTransformInitSchema, DualTransform from albumentations.core.types import ( BIG_INTEGER, @@ -38,16 +46,6 @@ from . import functional as fgeometric - -from albumentations.core.pydantic import ( - BorderModeType, - InterpolationType, - NonNegativeFloatRangeType, - ProbabilityType, - SymmetricRangeType, - check_1plus, -) - __all__ = [ "ShiftScaleRotate", "ElasticTransform", diff --git a/albumentations/augmentations/mixing/transforms.py b/albumentations/augmentations/mixing/transforms.py index b408e9820..5eda5f777 100644 --- a/albumentations/augmentations/mixing/transforms.py +++ b/albumentations/augmentations/mixing/transforms.py @@ -9,6 +9,7 @@ import numpy as np from albucore.functions import add_weighted from albucore.utils import is_grayscale_image +from pydantic import Field from typing_extensions import Annotated from albumentations.augmentations.mixing import functional as fmixing @@ -17,8 +18,6 @@ from albumentations.core.types import LENGTH_RAW_BBOX, BoxType, KeypointType, ReferenceImage, SizeType, Targets from albumentations.random_utils import beta -from pydantic import Field - __all__ = ["MixUp", "OverlayElements"] diff --git a/albumentations/augmentations/text/__init__.py b/albumentations/augmentations/text/__init__.py index 39b902595..9d447f1d7 100644 --- a/albumentations/augmentations/text/__init__.py +++ b/albumentations/augmentations/text/__init__.py @@ -1,2 +1,2 @@ -from .transforms import * from .functional import * +from .transforms import * diff --git a/albumentations/augmentations/text/functional.py b/albumentations/augmentations/text/functional.py index b88db44d8..76f8ec4dd 100644 --- a/albumentations/augmentations/text/functional.py +++ b/albumentations/augmentations/text/functional.py @@ -1,15 +1,14 @@ from __future__ import annotations + import random from typing import TYPE_CHECKING, Any, Sequence -from albucore.utils import preserve_channel_dim, MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS, NUM_RGB_CHANNELS -import cv2 - +import cv2 import numpy as np - -from albumentations.core.types import PAIR +from albucore.utils import MONO_CHANNEL_DIMENSIONS, NUM_MULTI_CHANNEL_DIMENSIONS, NUM_RGB_CHANNELS, preserve_channel_dim import albumentations.augmentations.functional as fmain +from albumentations.core.types import PAIR # Importing wordnet and other dependencies only for type checking if TYPE_CHECKING: @@ -89,7 +88,7 @@ def draw_text_on_pil_image(pil_image: Image, metadata_list: list[dict[str, Any]] def draw_text_on_multi_channel_image(image: np.ndarray, metadata_list: list[dict[str, Any]]) -> np.ndarray: """Draw text on a multi-channel image with more than three channels.""" try: - from PIL import ImageDraw, Image + from PIL import Image, ImageDraw except ImportError: raise ImportError("Pillow is not installed") from ImportError diff --git a/albumentations/augmentations/text/transforms.py b/albumentations/augmentations/text/transforms.py index 0667c216b..9c7e0ba98 100644 --- a/albumentations/augmentations/text/transforms.py +++ b/albumentations/augmentations/text/transforms.py @@ -1,21 +1,20 @@ from __future__ import annotations -from typing import Any, Literal import random +import re +from typing import Any, Literal + import numpy as np from PIL import ImageFont from pydantic import AfterValidator, model_validator - -import albumentations.augmentations.text.functional as ftext -import re from typing_extensions import Annotated, Self +import albumentations.augmentations.text.functional as ftext from albumentations.core.bbox_utils import check_bbox, denormalize_bbox from albumentations.core.pydantic import check_01, nondecreasing from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform from albumentations.core.types import BoxType, ColorType - __all__ = ["TextImage"] diff --git a/albumentations/augmentations/transforms.py b/albumentations/augmentations/transforms.py index e8f190da1..3968afc80 100644 --- a/albumentations/augmentations/transforms.py +++ b/albumentations/augmentations/transforms.py @@ -22,6 +22,19 @@ from albumentations.augmentations.blur.functional import blur from albumentations.augmentations.blur.transforms import BlurInitSchema, process_blur_limit from albumentations.augmentations.utils import check_range +from albumentations.core.pydantic import ( + InterpolationType, + NonNegativeFloatRangeType, + OnePlusFloatRangeType, + OnePlusIntRangeType, + ProbabilityType, + SymmetricRangeType, + ZeroOneRangeType, + check_0plus, + check_01, + check_1plus, + nondecreasing, +) from albumentations.core.transforms_interface import ( BaseTransformInitSchema, DualTransform, @@ -53,20 +66,6 @@ from . import functional as fmain -from albumentations.core.pydantic import ( - InterpolationType, - NonNegativeFloatRangeType, - OnePlusFloatRangeType, - OnePlusIntRangeType, - ProbabilityType, - SymmetricRangeType, - ZeroOneRangeType, - check_0plus, - check_01, - check_1plus, - nondecreasing, -) - __all__ = [ "Normalize", "RandomGamma", diff --git a/albumentations/core/keypoints_utils.py b/albumentations/core/keypoints_utils.py index e9fa8b9c0..cb1f0b844 100644 --- a/albumentations/core/keypoints_utils.py +++ b/albumentations/core/keypoints_utils.py @@ -3,9 +3,8 @@ import math from typing import Any, Sequence -from .utils import DataProcessor, Params - from .types import KeypointType +from .utils import DataProcessor, Params __all__ = [ "angle_to_2pi_range", diff --git a/albumentations/core/transforms_interface.py b/albumentations/core/transforms_interface.py index d02d586a6..940cf8c88 100644 --- a/albumentations/core/transforms_interface.py +++ b/albumentations/core/transforms_interface.py @@ -6,12 +6,13 @@ from warnings import warn import cv2 +import numpy as np from pydantic import BaseModel, ConfigDict, Field +from albumentations.core.pydantic import ProbabilityType from albumentations.core.validation import ValidatedTransformMeta from .serialization import Serializable, SerializableMeta, get_shortest_class_fullname -from albumentations.core.pydantic import ProbabilityType from .types import ( BoxInternalType, BoxType, @@ -22,8 +23,6 @@ ) from .utils import format_args -import numpy as np - __all__ = ["BasicTransform", "DualTransform", "ImageOnlyTransform", "NoOp", "ReferenceBasedTransform"] diff --git a/pyproject.toml b/pyproject.toml index 42db8f658..f618cf92c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,7 @@ [build-system] build-backend = "setuptools.build_meta" -requires = [ - "setuptools", - "wheel", -] +requires = [ "setuptools", "wheel" ] [tool.ruff] # Exclude a variety of commonly ignored directories. @@ -59,12 +56,8 @@ format.quote-style = "double" format.line-ending = "auto" format.skip-magic-trailing-comma = false # Like Black, automatically detect the appropriate line ending. -lint.select = [ - "ALL", -] +lint.select = [ "ALL" ] lint.ignore = [ - "ANN101", - "ANN102", "ANN204", "ANN401", "ARG001", @@ -88,24 +81,19 @@ lint.ignore = [ "FBT002", "FBT003", "G004", - "I001", "PLR0913", "PTH123", "S311", "TCH001", "TCH002", - "TCH003", "TRY003", ] # Allow fix for all enabled rules (when `--fix`) is provided. lint.explicit-preview-rules = true -lint.fixable = [ - "ALL", -] -lint.unfixable = [ -] +lint.fixable = [ "ALL" ] +lint.unfixable = [ ] # Allow unused variables when underscore-prefixed. lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" # Like Black, use double quotes for strings.