Skip to content

Commit

Permalink
Deleted update_params (#2267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ternaus authored Jan 8, 2025
1 parent d0f56c5 commit 669b60f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
4 changes: 0 additions & 4 deletions albumentations/augmentations/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2199,10 +2199,6 @@ class GaussNoise(ImageOnlyTransform):
mean_range (tuple[float, float]): Range for noise mean as a fraction
of the maximum value (255 for uint8 images or 1.0 for float images).
Values should be in range [-1, 1]. Default: (0.0, 0.0).
var_limit (tuple[float, float] | float): [Deprecated] Variance range for noise.
If var_limit is a single float value, the range will be (0, var_limit).
Default: (10.0, 50.0).
mean (float): [Deprecated] Mean of the noise. Default: 0.
per_channel (bool): If True, noise will be sampled for each channel independently.
Otherwise, the noise will be sampled once for all channels. Default: True.
noise_scale_factor (float): Scaling factor for noise generation. Value should be in the range (0, 1].
Expand Down
40 changes: 20 additions & 20 deletions albumentations/core/transforms_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __call__(self, *args: Any, force_apply: bool = False, **kwargs: Any) -> Any:

if self.should_apply(force_apply=force_apply):
params = self.get_params()
params = self.update_params_shape(params=params, data=kwargs)
params = self.update_transform_params(params=params, data=kwargs)

if self.targets_as_params: # check if all required targets are in kwargs.
missing_keys = set(self.targets_as_params).difference(kwargs.keys())
Expand Down Expand Up @@ -173,7 +173,6 @@ def should_apply(self, force_apply: bool = False) -> bool:

def apply_with_params(self, params: dict[str, Any], *args: Any, **kwargs: Any) -> dict[str, Any]:
"""Apply transforms with parameters."""
params = self.update_params(params, **kwargs) # remove after move parameters like interpolation
res = {}
for key, arg in kwargs.items():
if key in self._key2func and arg is not None:
Expand Down Expand Up @@ -248,8 +247,16 @@ def get_params(self) -> dict[str, Any]:
"""Returns parameters independent of input."""
return {}

def update_params_shape(self, params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:
"""Updates parameters with input shape."""
def update_transform_params(self, params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:
"""Updates parameters with input shape and transform-specific params.
Args:
params: Parameters to be updated
data: Input data dictionary containing images/volumes
Returns:
Updated parameters dictionary with shape and transform-specific params
"""
# Extract shape from volume, volumes, image, or images
if "volume" in data:
shape = data["volume"][0].shape # Take first slice of volume
Expand All @@ -262,6 +269,15 @@ def update_params_shape(self, params: dict[str, Any], data: dict[str, Any]) -> d

# For volumes/images, shape will be either (H, W) or (H, W, C)
params["shape"] = shape

# Add transform-specific params
if hasattr(self, "interpolation"):
params["interpolation"] = self.interpolation
if hasattr(self, "fill"):
params["fill"] = self.fill
if hasattr(self, "fill_mask"):
params["fill_mask"] = self.fill_mask

return params

def get_params_dependent_on_data(self, params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:
Expand Down Expand Up @@ -293,22 +309,6 @@ def available_keys(self) -> set[str]:
"""Returns set of available keys."""
return self._available_keys

def update_params(self, params: dict[str, Any], **kwargs: Any) -> dict[str, Any]:
"""Update parameters with transform specific params.
This method is deprecated, use:
- `get_params` for transform specific params like interpolation and
- `update_params_shape` for data like shape.
"""
if hasattr(self, "interpolation"):
params["interpolation"] = self.interpolation
if hasattr(self, "fill"):
params["fill"] = self.fill
if hasattr(self, "fill_mask"):
params["fill_mask"] = self.fill_mask

# Use update_params_shape to get shape consistently
return self.update_params_shape(params, kwargs)

def add_targets(self, additional_targets: dict[str, str]) -> None:
"""Add targets to transform them the same way as one of existing targets.
ex: {'target_image': 'image'}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def test_affine_scale_ratio(params):

data = {"image": image}
call_params = aug.get_params()
call_params = aug.update_params_shape(call_params, data)
call_params = aug.update_transform_params(call_params, data)

apply_params = aug.get_params_dependent_on_data(params=call_params, data=data)

Expand Down

0 comments on commit 669b60f

Please sign in to comment.