Skip to content

Commit

Permalink
Update python (#1984)
Browse files Browse the repository at this point in the history
* Empty-Commit

* Updating python

* More fixes

* Fix

* Cleanup

* Raised pytorch version

* Removed test for python 3.13
  • Loading branch information
ternaus authored Oct 9, 2024
1 parent 47f9592 commit 1ad56dc
Show file tree
Hide file tree
Showing 56 changed files with 3,570 additions and 2,189 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12"]
include:
- operating-system: ubuntu-latest
path: ~/.cache/pip
Expand Down Expand Up @@ -54,11 +54,11 @@ jobs:
matrix.operating-system == 'ubuntu-latest' ||
matrix.operating-system == 'windows-latest'
run: >
uv pip install --system --verbose torch==2.3.1+cpu torchvision==0.18.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu
uv pip install --system --verbose torch==2.4.1+cpu torchvision==0.19.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu
- name: Install PyTorch on MacOS
if: matrix.operating-system == 'macos-latest'
run: >
uv pip install --system --verbose torch==2.3.1 torchvision==0.18.1
uv pip install --system --verbose torch==2.4.1 torchvision==0.19.1
- name: Install dev requirements
run: uv pip install --system -r requirements-dev.txt
- name: Install dependencies
Expand All @@ -79,7 +79,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.8"]
python-version: ["3.9"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -105,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ formats:
- epub

python:
version: 3.8
version: 3.9
system_packages: true
install:
- requirements: docs/requirements.txt
3 changes: 2 additions & 1 deletion albumentations/augmentations/blur/functional.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from collections.abc import Sequence
from itertools import product
from math import ceil
from typing import Literal, Sequence
from typing import Literal

import cv2
import numpy as np
Expand Down
30 changes: 15 additions & 15 deletions albumentations/augmentations/blur/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import random
import warnings
from typing import Any, Literal, Tuple, cast
from typing import Any, Literal, cast

import cv2
import numpy as np
Expand Down Expand Up @@ -97,7 +97,7 @@ class InitSchema(BlurInitSchema):

def __init__(self, blur_limit: ScaleIntType = (3, 7), p: float = 0.5, always_apply: bool | None = None):
super().__init__(p=p, always_apply=always_apply)
self.blur_limit = cast(Tuple[int, int], blur_limit)
self.blur_limit = cast(tuple[int, int], blur_limit)

def apply(self, img: np.ndarray, kernel: int, **params: Any) -> np.ndarray:
return fblur.blur(img, kernel)
Expand Down Expand Up @@ -187,7 +187,7 @@ def __init__(
):
super().__init__(blur_limit=blur_limit, p=p, always_apply=always_apply)
self.allow_shifted = allow_shifted
self.blur_limit = cast(Tuple[int, int], blur_limit)
self.blur_limit = cast(tuple[int, int], blur_limit)

def get_transform_init_args_names(self) -> tuple[str, ...]:
return (*super().get_transform_init_args_names(), "allow_shifted")
Expand Down Expand Up @@ -387,8 +387,8 @@ def __init__(
p: float = 0.5,
):
super().__init__(p, always_apply)
self.blur_limit = cast(Tuple[int, int], blur_limit)
self.sigma_limit = cast(Tuple[float, float], sigma_limit)
self.blur_limit = cast(tuple[int, int], blur_limit)
self.sigma_limit = cast(tuple[float, float], sigma_limit)

def apply(self, img: np.ndarray, ksize: int, sigma: float, **params: Any) -> np.ndarray:
return fblur.gaussian_blur(img, ksize, sigma=sigma)
Expand Down Expand Up @@ -639,12 +639,12 @@ def __init__(
warnings.warn("sigmaY_limit is deprecated; use sigma_y_limit instead.", DeprecationWarning, stacklevel=2)
sigma_y_limit = sigmaY_limit

self.blur_limit = cast(Tuple[int, int], blur_limit)
self.sigma_x_limit = cast(Tuple[float, float], sigma_x_limit)
self.sigma_y_limit = cast(Tuple[float, float], sigma_y_limit)
self.rotate_limit = cast(Tuple[int, int], rotate_limit)
self.beta_limit = cast(Tuple[float, float], beta_limit)
self.noise_limit = cast(Tuple[float, float], noise_limit)
self.blur_limit = cast(tuple[int, int], blur_limit)
self.sigma_x_limit = cast(tuple[float, float], sigma_x_limit)
self.sigma_y_limit = cast(tuple[float, float], sigma_y_limit)
self.rotate_limit = cast(tuple[int, int], rotate_limit)
self.beta_limit = cast(tuple[float, float], beta_limit)
self.noise_limit = cast(tuple[float, float], noise_limit)

def apply(self, img: np.ndarray, kernel: np.ndarray, **params: Any) -> np.ndarray:
return fmain.convolve(img, kernel=kernel)
Expand Down Expand Up @@ -754,8 +754,8 @@ def __init__(
p: float = 0.5,
):
super().__init__(p, always_apply)
self.radius = cast(Tuple[int, int], radius)
self.alias_blur = cast(Tuple[float, float], alias_blur)
self.radius = cast(tuple[int, int], radius)
self.alias_blur = cast(tuple[float, float], alias_blur)

def apply(self, img: np.ndarray, radius: int, alias_blur: float, **params: Any) -> np.ndarray:
return fblur.defocus(img, radius, alias_blur)
Expand Down Expand Up @@ -804,8 +804,8 @@ def __init__(
p: float = 0.5,
):
super().__init__(p, always_apply)
self.max_factor = cast(Tuple[float, float], max_factor)
self.step_factor = cast(Tuple[float, float], step_factor)
self.max_factor = cast(tuple[float, float], max_factor)
self.step_factor = cast(tuple[float, float], step_factor)

def apply(self, img: np.ndarray, zoom_factors: np.ndarray, **params: Any) -> np.ndarray:
return fblur.zoom_blur(img, zoom_factors)
Expand Down
2 changes: 1 addition & 1 deletion albumentations/augmentations/crops/functional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Sequence
from collections.abc import Sequence

import cv2
import numpy as np
Expand Down
11 changes: 6 additions & 5 deletions albumentations/augmentations/crops/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import math
import random
from typing import Any, Sequence, Tuple, cast
from collections.abc import Sequence
from typing import Annotated, Any, cast
from warnings import warn

import cv2
import numpy as np
from pydantic import AfterValidator, Field, field_validator, model_validator
from typing_extensions import Annotated, Self
from typing_extensions import Self

from albumentations.augmentations.geometric import functional as fgeometric
from albumentations.core.bbox_utils import union_of_bboxes
Expand Down Expand Up @@ -583,7 +584,7 @@ def __init__(
always_apply: bool | None = None,
p: float = 1.0,
):
super().__init__(size=cast(Tuple[int, int], size), interpolation=interpolation, p=p, always_apply=always_apply)
super().__init__(size=cast(tuple[int, int], size), interpolation=interpolation, p=p, always_apply=always_apply)
self.min_max_height = min_max_height
self.w2h_ratio = w2h_ratio

Expand Down Expand Up @@ -714,7 +715,7 @@ def __init__(
always_apply: bool | None = None,
p: float = 1.0,
):
super().__init__(size=cast(Tuple[int, int], size), interpolation=interpolation, p=p, always_apply=always_apply)
super().__init__(size=cast(tuple[int, int], size), interpolation=interpolation, p=p, always_apply=always_apply)
self.scale = scale
self.ratio = ratio

Expand Down Expand Up @@ -828,7 +829,7 @@ def __init__(
# Ensure the new parameter is used even if the old one is passed
cropping_bbox_key = cropping_box_key

self.max_part_shift = cast(Tuple[float, float], max_part_shift)
self.max_part_shift = cast(tuple[float, float], max_part_shift)
self.cropping_bbox_key = cropping_bbox_key

def get_params_dependent_on_data(
Expand Down
8 changes: 4 additions & 4 deletions albumentations/augmentations/domain_adaptation/transforms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import random
from typing import Any, Callable, Literal, Sequence, Tuple, cast
from collections.abc import Sequence
from typing import Annotated, Any, Callable, Literal, cast

import cv2
import numpy as np
from albucore import add_weighted, get_num_channels
from pydantic import AfterValidator, Field, field_validator
from typing_extensions import Annotated

import albumentations.augmentations.geometric.functional as fgeometric
from albumentations.augmentations.domain_adaptation.functional import (
Expand Down Expand Up @@ -205,7 +205,7 @@ def __init__(
super().__init__(p=p, always_apply=always_apply)
self.reference_images = reference_images
self.read_fn = read_fn
self.beta_limit = cast(Tuple[float, float], beta_limit)
self.beta_limit = cast(tuple[float, float], beta_limit)

def apply(
self,
Expand Down Expand Up @@ -468,7 +468,7 @@ def __init__(
):
super().__init__(p=p, always_apply=always_apply)
self.templates = templates
self.img_weight = cast(Tuple[float, float], img_weight)
self.img_weight = cast(tuple[float, float], img_weight)
self.template_transform = template_transform
self.name = name

Expand Down
4 changes: 2 additions & 2 deletions albumentations/augmentations/dropout/channel_dropout.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import random
from typing import Any, Mapping
from collections.abc import Mapping
from typing import Annotated, Any

import numpy as np
from albucore import get_num_channels
from pydantic import AfterValidator, Field
from typing_extensions import Annotated

from albumentations.core.pydantic import check_1plus
from albumentations.core.transforms_interface import BaseTransformInitSchema, ImageOnlyTransform
Expand Down
4 changes: 2 additions & 2 deletions albumentations/augmentations/dropout/coarse_dropout.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import random
from typing import Any
from typing import Annotated, Any
from warnings import warn

import numpy as np
from pydantic import AfterValidator, Field, model_validator
from typing_extensions import Annotated, Literal, Self
from typing_extensions import Literal, Self

from albumentations import random_utils
from albumentations.augmentations.dropout.transforms import BaseDropout
Expand Down
4 changes: 2 additions & 2 deletions albumentations/augmentations/dropout/grid_dropout.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from typing import Any, Literal
from typing import Annotated, Any, Literal
from warnings import warn

from pydantic import AfterValidator, Field, model_validator
from typing_extensions import Annotated, Self
from typing_extensions import Self

import albumentations.augmentations.dropout.functional as fdropout
from albumentations import random_utils
Expand Down
5 changes: 2 additions & 3 deletions albumentations/augmentations/dropout/mask_dropout.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

import random
from typing import Any, Tuple, cast
from typing import Any, Literal, cast

import cv2
import numpy as np
from skimage.measure import label
from typing_extensions import Literal

import albumentations.augmentations.dropout.functional as fdropout
from albumentations.core.bbox_utils import BboxProcessor, denormalize_bboxes, normalize_bboxes
Expand Down Expand Up @@ -88,7 +87,7 @@ def __init__(
p: float = 0.5,
):
super().__init__(p=p, always_apply=always_apply)
self.max_objects = cast(Tuple[int, int], max_objects)
self.max_objects = cast(tuple[int, int], max_objects)
self.image_fill_value = image_fill_value
self.mask_fill_value = mask_fill_value

Expand Down
10 changes: 5 additions & 5 deletions albumentations/augmentations/dropout/xy_masking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import random
from typing import Any, Tuple, cast
from typing import Any, cast

import numpy as np
from pydantic import model_validator
Expand Down Expand Up @@ -86,11 +86,11 @@ def __init__(
p: float = 0.5,
):
super().__init__(p=p, always_apply=always_apply, fill_value=fill_value, mask_fill_value=mask_fill_value)
self.num_masks_x = cast(Tuple[int, int], num_masks_x)
self.num_masks_y = cast(Tuple[int, int], num_masks_y)
self.num_masks_x = cast(tuple[int, int], num_masks_x)
self.num_masks_y = cast(tuple[int, int], num_masks_y)

self.mask_x_length = cast(Tuple[int, int], mask_x_length)
self.mask_y_length = cast(Tuple[int, int], mask_y_length)
self.mask_x_length = cast(tuple[int, int], mask_x_length)
self.mask_y_length = cast(tuple[int, int], mask_y_length)

def validate_mask_length(
self,
Expand Down
3 changes: 2 additions & 1 deletion albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections import defaultdict
from typing import Any, Literal, Sequence
from collections.abc import Sequence
from typing import Any, Literal
from warnings import warn

import cv2
Expand Down
7 changes: 4 additions & 3 deletions albumentations/augmentations/geometric/functional.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import math
from typing import Any, Callable, Literal, Sequence, Tuple, TypedDict, cast
from collections.abc import Sequence
from typing import Any, Callable, Literal, TypedDict, cast

import cv2
import numpy as np
Expand Down Expand Up @@ -2399,7 +2400,7 @@ def compute_affine_warp_output_shape(
height, width = input_shape[:2]

if height == 0 or width == 0:
return matrix, cast(Tuple[int, int], input_shape[:2])
return matrix, cast(tuple[int, int], input_shape[:2])

min_coords, max_coords = compute_transformed_image_bounds(matrix, (height, width))
minc, minr = min_coords
Expand All @@ -2418,7 +2419,7 @@ def compute_affine_warp_output_shape(
translation = -minc, -minr
matrix_to_fit = skimage.transform.SimilarityTransform(translation=translation)
matrix += matrix_to_fit
return matrix, cast(Tuple[int, int], output_shape_tuple)
return matrix, cast(tuple[int, int], output_shape_tuple)


def center(image_shape: tuple[int, int]) -> tuple[float, float]:
Expand Down
7 changes: 4 additions & 3 deletions albumentations/augmentations/geometric/resize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import random
from typing import Any, List, Sequence, Tuple, Union, cast
from collections.abc import Sequence
from typing import Any, Union, cast

import cv2
import numpy as np
Expand Down Expand Up @@ -78,7 +79,7 @@ def __init__(
p: float = 0.5,
):
super().__init__(p=p, always_apply=always_apply)
self.scale_limit = cast(Tuple[float, float], scale_limit)
self.scale_limit = cast(tuple[float, float], scale_limit)
self.interpolation = interpolation

def get_params(self) -> dict[str, float]:
Expand Down Expand Up @@ -129,7 +130,7 @@ def check_scale_limit(cls, v: ScaleIntType, info: ValidationInfo) -> int | list[
if not value >= 1:
raise ValueError(f"{info.field_name} must be bigger or equal to 1.")

return cast(Union[int, List[int]], result)
return cast(Union[int, list[int]], result)


class LongestMaxSize(DualTransform):
Expand Down
Loading

0 comments on commit 1ad56dc

Please sign in to comment.