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

updated random fog #2259

Merged
merged 1 commit 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
34 changes: 0 additions & 34 deletions albumentations/augmentations/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,14 +925,6 @@ class RandomFog(ImageOnlyTransform):
"""

class InitSchema(BaseTransformInitSchema):
fog_coef_lower: float | None = Field(
ge=0,
le=1,
)
fog_coef_upper: float | None = Field(
ge=0,
le=1,
)
fog_coef_range: Annotated[
tuple[float, float],
AfterValidator(check_range_bounds(0, 1)),
Expand All @@ -941,34 +933,8 @@ class InitSchema(BaseTransformInitSchema):

alpha_coef: float = Field(ge=0, le=1)

@model_validator(mode="after")
def validate_fog_coefficients(self) -> Self:
if self.fog_coef_lower is not None:
warn(
"`fog_coef_lower` is deprecated, use `fog_coef_range` instead.",
DeprecationWarning,
stacklevel=2,
)
if self.fog_coef_upper is not None:
warn(
"`fog_coef_upper` is deprecated, use `fog_coef_range` instead.",
DeprecationWarning,
stacklevel=2,
)

lower = self.fog_coef_lower if self.fog_coef_lower is not None else self.fog_coef_range[0]
upper = self.fog_coef_upper if self.fog_coef_upper is not None else self.fog_coef_range[1]
self.fog_coef_range = (lower, upper)

self.fog_coef_lower = None
self.fog_coef_upper = None

return self

def __init__(
self,
fog_coef_lower: float | None = None,
fog_coef_upper: float | None = None,
alpha_coef: float = 0.08,
fog_coef_range: tuple[float, float] = (0.3, 1),
p: float = 0.5,
Expand Down
18 changes: 0 additions & 18 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,24 +1734,6 @@ def test_crop_and_pad_px_pixel_values(px, expected_shape):
assert np.all(transformed_image == cropped_region)


@pytest.mark.parametrize(
"params, expected",
[
# Test default initialization values
({}, {"fog_coef_range": (0.3, 1)}),
# Test fog coefficient range
({"fog_coef_range": (0.4, 0.7)}, {"fog_coef_range": (0.4, 0.7)}),
# Deprecated fog coefficient values handling
({"fog_coef_lower": 0.2}, {"fog_coef_range": (0.2, 1)}),
({"fog_coef_upper": 0.6}, {"fog_coef_range": (0.3, 0.6)}),
],
)
def test_random_fog_initialization(params, expected):
img_fog = A.RandomFog(**params)
for key, value in expected.items():
assert getattr(img_fog, key) == value, f"Failed on {key} with value {value}"


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