MinMaxNormalize#
- class MinMaxNormalize[source]#
Bases:
ImageOnlyTransformAlbumentations transform that normalizes image to desired min and max values.
This will shift and scale the image appropriately to achieve the desired min and max.
Attributes
Returns set of available keys.
Targets used to get params dependent on targets.
- __init__(min_val=0.0, max_val=1.0, dtype=5, p=1.0)[source]#
Constructor.
- Parameters
min_val – the minimum value that output should have
max_val – the maximum value that output should have
dtype – the dtype of output image
Methods
__init__([min_val, max_val, dtype, p])Constructor.
add_targets(additional_targets)Add targets to transform them the same way as one of existing targets.
apply(image, **params)Apply transform on image.
apply_to_images(images, *args, **params)Apply transform on images.
apply_to_volume(volume, *args, **params)Apply transform slice by slice to a volume.
apply_to_volumes(volumes, *args, **params)Apply transform to multiple volumes.
apply_with_params(params, *args, **kwargs)Apply transforms with parameters.
Returns the parameters that were used in the last transform application.
Returns base init args - p
Returns parameters independent of input.
get_params_dependent_on_data(params, data)Returns parameters dependent on input.
get_processor(key)Exclude seed from init args during serialization
Returns names of arguments that are used in __init__ method of the transform.
set_deterministic(flag[, save_key])Set transform to be deterministic.
set_processors(processors)set_random_seed(seed)Set random state from seed.
set_random_state(random_generator, py_random)Set random state directly from generators.
should_apply([force_apply])to_dict([on_not_implemented_error])Take a transform pipeline and convert it to a serializable representation that uses only standard python data types: dictionaries, lists, strings, integers, and floats.
Returns a dictionary representation of the transform, excluding internal parameters.
update_transform_params(params, data)Updates parameters with input shape and transform-specific params.
- pydantic model InitSchema#
Bases:
BaseTransformInitSchemaShow JSON schema
{ "title": "InitSchema", "type": "object", "properties": { "p": { "maximum": 1.0, "minimum": 0.0, "title": "P", "type": "number" }, "strict": { "default": false, "title": "Strict", "type": "boolean" } }, "required": [ "p" ] }
- Config
arbitrary_types_allowed: bool = True
- Fields
p (float)strict (bool)
- copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) Self#
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `- Parameters
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns
A copy of the model with included, excluded and updated fields as specified.
- Return type
Self
- dict(*, include: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, exclude: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) Dict[str, Any]#
- Parameters
include (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) –
exclude (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type
- json(*, include: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, exclude: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) str#
- Parameters
include (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) –
exclude (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) –
by_alias (bool) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type
- classmethod model_construct(_fields_set: set[str] | None = None, **values: Any) Self#
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns
A new instance of the Model class with validated data.
- Return type
- model_copy(*, update: Optional[Mapping[str, Any]] = None, deep: bool = False) Self#
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy
Returns a copy of the model.
- model_dump(*, mode: Union[Literal['json', 'python'], str] = 'python', include: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, exclude: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, context: Any | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: Union[bool, Literal['none', 'warn', 'error']] = True, serialize_as_any: bool = False) dict[str, Any]#
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters
mode (Union[Literal['json', 'python'], str]) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) – A set of fields to include in the output.
exclude (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (Union[bool, Literal['none', 'warn', 'error']]) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns
A dictionary representation of the model.
- Return type
- model_dump_json(*, indent: int | None = None, include: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, exclude: Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]] = None, context: Any | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: Union[bool, Literal['none', 'warn', 'error']] = True, serialize_as_any: bool = False) str#
Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
include (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) – Field(s) to include in the JSON output.
exclude (Optional[Union[Set[int], Set[str], Mapping[int, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]], Mapping[str, Union[Set[int], Set[str], Mapping[int, Union[IncEx, bool]], Mapping[str, Union[IncEx, bool]], bool]]]]) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (Union[bool, Literal['none', 'warn', 'error']]) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
- Returns
A JSON string representation of the model.
- Return type
- classmethod model_json_schema(by_alias: bool = True, ref_template: str = '#/$defs/{model}', schema_generator: type[pydantic.json_schema.GenerateJsonSchema] = <class 'pydantic.json_schema.GenerateJsonSchema'>, mode: ~typing.Literal['validation', 'serialization'] = 'validation') dict[str, Any]#
Generates a JSON schema for a model class.
- Parameters
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
schema_generator (type[pydantic.json_schema.GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns
The JSON schema for the given model class.
- Return type
- classmethod model_parametrized_name(params: tuple[type[Any], ...]) str#
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns
String representing the new class where params are passed to cls as type variables.
- Raises
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type
- model_post_init(_BaseModel__context: Any) None#
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Parameters
_BaseModel__context (Any) –
- Return type
None
- classmethod model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) bool | None#
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type
bool | None
- classmethod model_validate(obj: Any, *, strict: bool | None = None, from_attributes: bool | None = None, context: Any | None = None) Self#
Validate a pydantic model instance.
- Parameters
- Raises
ValidationError – If the object could not be validated.
- Returns
The validated model instance.
- Return type
- classmethod model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, context: Any | None = None) Self#
Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters
- Returns
The validated Pydantic model.
- Raises
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type
- classmethod model_validate_strings(obj: Any, *, strict: bool | None = None, context: Any | None = None) Self#
Validate the given object with string data against the Pydantic model.
- classmethod parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) Self#
- classmethod parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) Self#
- classmethod schema_json(*, by_alias: bool = True, ref_template: str = '#/$defs/{model}', **dumps_kwargs: Any) str#
- __init__(min_val=0.0, max_val=1.0, dtype=5, p=1.0)[source]#
Constructor.
- Parameters
min_val – the minimum value that output should have
max_val – the maximum value that output should have
dtype – the dtype of output image
- add_targets(additional_targets: dict[str, str]) None#
Add targets to transform them the same way as one of existing targets. ex: {‘target_image’: ‘image’} ex: {‘obj1_mask’: ‘mask’, ‘obj2_mask’: ‘mask’} by the way you must have at least one object with key ‘image’
- Parameters
additional_targets (dict) – keys - new target name, values - old target name. ex: {‘image2’: ‘image’}
- Return type
None
- apply_to_images(images: ndarray, *args: Any, **params: Any) ndarray#
Apply transform on images.
- Parameters
- Returns
Transformed images as numpy array in the same format as input
- Return type
- apply_to_volume(volume: ndarray, *args: Any, **params: Any) ndarray#
Apply transform slice by slice to a volume.
- Parameters
- Returns
Transformed volume as numpy array in the same format as input
- Return type
- apply_to_volumes(volumes: ndarray, *args: Any, **params: Any) ndarray#
Apply transform to multiple volumes.
- apply_with_params(params: dict[str, Any], *args: Any, **kwargs: Any) dict[str, Any]#
Apply transforms with parameters.
- get_applied_params() dict[str, Any]#
Returns the parameters that were used in the last transform application. Returns empty dict if transform was not applied.
- get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#
Returns parameters dependent on input.
- get_processor(key: str) albumentations.core.bbox_utils.BboxProcessor | albumentations.core.keypoints_utils.KeypointsProcessor | None#
- Parameters
key (str) –
- Return type
albumentations.core.bbox_utils.BboxProcessor | albumentations.core.keypoints_utils.KeypointsProcessor | None
- get_transform_init_args_names()[source]#
Returns names of arguments that are used in __init__ method of the transform.
- set_deterministic(flag: bool, save_key: str = 'replay') BasicTransform#
Set transform to be deterministic.
- set_processors(processors: dict[str, albumentations.core.bbox_utils.BboxProcessor | albumentations.core.keypoints_utils.KeypointsProcessor]) None#
- set_random_seed(seed: int | None) None#
Set random state from seed.
- Parameters
seed (int | None) – Random seed to use
- Return type
None
- set_random_state(random_generator: Generator, py_random: Random) None#
Set random state directly from generators.
- to_dict(on_not_implemented_error: str = 'raise') dict[str, Any]#
Take a transform pipeline and convert it to a serializable representation that uses only standard python data types: dictionaries, lists, strings, integers, and floats.
- Parameters
self – A transform that should be serialized. If the transform doesn’t implement the to_dict method and on_not_implemented_error equals to ‘raise’ then NotImplementedError is raised. If on_not_implemented_error equals to ‘warn’ then NotImplementedError will be ignored but no transform parameters will be serialized.
on_not_implemented_error (str) – raise or warn.
- Return type
- to_dict_private() dict[str, Any]#
Returns a dictionary representation of the transform, excluding internal parameters.
- update_transform_params(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#
Updates parameters with input shape and transform-specific params.
- applied_in_replay = False#
- call_backup = None#
- replay_mode = False#
- save_key = 'replay'#