Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update random snow #2257

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions albumentations/augmentations/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,52 +456,11 @@ class InitSchema(BaseTransformInitSchema):
AfterValidator(nondecreasing),
]

snow_point_lower: float | None = Field(
gt=0,
lt=1,
)
snow_point_upper: float | None = Field(
gt=0,
lt=1,
)
brightness_coeff: float = Field(gt=0)
method: Literal["bleach", "texture"]
ternaus marked this conversation as resolved.
Show resolved Hide resolved

@model_validator(mode="after")
def validate_ranges(self) -> Self:
if self.snow_point_lower is not None or self.snow_point_upper is not None:
if self.snow_point_lower is not None:
warn(
"`snow_point_lower` deprecated. Use `snow_point_range` as tuple"
" (snow_point_lower, snow_point_upper) instead.",
DeprecationWarning,
stacklevel=2,
)
if self.snow_point_upper is not None:
warn(
"`snow_point_upper` deprecated. Use `snow_point_range` as tuple"
"(snow_point_lower, snow_point_upper) instead.",
DeprecationWarning,
stacklevel=2,
)
lower = self.snow_point_lower if self.snow_point_lower is not None else self.snow_point_range[0]
upper = self.snow_point_upper if self.snow_point_upper is not None else self.snow_point_range[1]
self.snow_point_range = (lower, upper)
self.snow_point_lower = None
self.snow_point_upper = None

# Validate the snow_point_range
if not (0 < self.snow_point_range[0] <= self.snow_point_range[1] < 1):
raise ValueError(
"snow_point_range values should be increasing within (0, 1) range.",
)

return self

def __init__(
self,
snow_point_lower: float | None = None,
snow_point_upper: float | None = None,
brightness_coeff: float = 2.5,
snow_point_range: tuple[float, float] = (0.1, 0.3),
method: Literal["bleach", "texture"] = "bleach",
Expand Down
18 changes: 0 additions & 18 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,24 +1508,6 @@ def test_random_rain_invalid_input(params):
A.RandomRain(**params)

ternaus marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.parametrize(
"params, expected",
[
# Test default initialization values
({}, {"snow_point_range": (0.1, 0.3)}),
# Test snow point range
({"snow_point_range": (0.2, 0.6)}, {"snow_point_range": (0.2, 0.6)}),
# Deprecated quality values handling
({"snow_point_lower": 0.15}, {"snow_point_range": (0.15, 0.3)}),
({"snow_point_upper": 0.4}, {"snow_point_range": (0.1, 0.4)}),
],
)
def test_random_snow_initialization(params, expected):
img_comp = A.RandomSnow(**params)
for key, value in expected.items():
assert getattr(img_comp, key) == value, f"Failed on {key} with value {value}"


@pytest.mark.parametrize(
"params",
[
Expand Down
Loading