Centralised normalisation parameter bounds and defaults.
Defines the valid ranges and default values for normalisation
parameters. Used by both the UI widget and validate_config so
that limits are enforced consistently whether the user configures
via the GUI or programmatically.
validate_normalisation(norm_cfg)
Validate normalisation parameters against bounds.
Works with both DotMap and plain dict, so it can be called
from validate_config (full cfg) and from the UI widget
(extracted dict).
Parameters:
| Name |
Type |
Description |
Default |
norm_cfg
|
dict
|
Dict-like with normalisation fields (image_size,
interpolation_order, n_output_channels,
norm_asinh_scale, norm_asinh_clip).
|
required
|
Returns:
| Type |
Description |
list[str]
|
List of error strings, empty if all valid.
|
Source code in anomaly_match/utils/normalisation_parameters.py
| def validate_normalisation(norm_cfg: dict) -> list[str]:
"""Validate normalisation parameters against bounds.
Works with both ``DotMap`` and plain dict, so it can be called
from ``validate_config`` (full cfg) and from the UI widget
(extracted dict).
Args:
norm_cfg: Dict-like with normalisation fields (``image_size``,
``interpolation_order``, ``n_output_channels``,
``norm_asinh_scale``, ``norm_asinh_clip``).
Returns:
List of error strings, empty if all valid.
"""
errors: list[str] = []
size = norm_cfg.get("image_size")
if size is not None:
h = size[0] if isinstance(size, (list, tuple)) else size
if not (RESOLUTION_MIN <= h <= RESOLUTION_MAX):
errors.append(f"image_size {h} outside [{RESOLUTION_MIN}, {RESOLUTION_MAX}]")
interp = norm_cfg.get("interpolation_order")
if interp is not None and not (INTERPOLATION_MIN <= interp <= INTERPOLATION_MAX):
errors.append(
f"interpolation_order {interp} outside [{INTERPOLATION_MIN}, {INTERPOLATION_MAX}]"
)
n_ch = norm_cfg.get("n_output_channels")
if n_ch is not None and not (N_OUTPUT_CHANNELS_MIN <= n_ch <= N_OUTPUT_CHANNELS_MAX):
errors.append(
f"n_output_channels {n_ch} outside [{N_OUTPUT_CHANNELS_MIN}, {N_OUTPUT_CHANNELS_MAX}]"
)
pad = norm_cfg.get("cutout_padding_factor")
if pad is not None and not (CUTOUT_PADDING_FACTOR_MIN <= pad <= CUTOUT_PADDING_FACTOR_MAX):
errors.append(
f"cutout_padding_factor {pad} outside "
f"[{CUTOUT_PADDING_FACTOR_MIN}, {CUTOUT_PADDING_FACTOR_MAX}]"
)
for values, name, lo, hi in [
(norm_cfg.get("norm_asinh_scale"), "norm_asinh_scale", ASINH_SCALE_MIN, ASINH_SCALE_MAX),
(norm_cfg.get("norm_asinh_clip"), "norm_asinh_clip", ASINH_CLIP_MIN, ASINH_CLIP_MAX),
]:
if values is not None:
for i, v in enumerate(values):
if not (lo <= v <= hi):
errors.append(f"{name}[{i}]={v} outside [{lo}, {hi}]")
return errors
|