MinMaxNormalize#

class MinMaxNormalize[source]#

Bases: ImageOnlyTransform

Albumentations 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

applied_in_replay

available_keys

Returns set of available keys.

call_backup

deterministic

replay_mode

save_key

targets

targets_as_params

Targets used to get params dependent on targets.

__init__(min_val=0.0, max_val=1.0, dtype=5, always_apply=False, 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, ...])

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, **params)

Apply transform on images.

apply_with_params(params, *args, **kwargs)

Apply transforms with parameters.

get_base_init_args()

Returns base init args - p

get_class_fullname()

get_dict_with_id()

get_params()

Returns parameters independent of input.

get_params_dependent_on_data(params, data)

Returns parameters dependent on input.

get_params_dependent_on_targets(params)

This method is deprecated.

get_transform_init_args()

get_transform_init_args_names()

Returns names of arguments that are used in __init__ method of the transform.

is_serializable()

set_deterministic(flag[, save_key])

Set transform to be deterministic.

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.

to_dict_private()

update_params(params, **kwargs)

Update parameters with transform specific params.

update_params_shape(params, data)

Updates parameters with input image shape.

pydantic model InitSchema#

Bases: BaseTransformInitSchema

Show JSON schema
{
   "title": "InitSchema",
   "type": "object",
   "properties": {
      "always_apply": {
         "anyOf": [
            {
               "type": "boolean"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "deprecated": true,
         "title": "Always Apply"
      },
      "p": {
         "default": 0.5,
         "description": "Probability of applying the transform",
         "maximum": 1.0,
         "minimum": 0.0,
         "title": "P",
         "type": "number"
      }
   }
}

Config:
  • arbitrary_types_allowed: bool = True

Fields:
  • always_apply (bool | None)

  • p (float)

field p: ProbabilityType = 0.5#

Probability of applying the transform

Constraints:
  • ge = 0

  • le = 1

classmethod construct(_fields_set: set[str] | None = None, **values: Any) Self#
Parameters:
  • _fields_set (set[str] | None) –

  • values (Any) –

Return type:

Self

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:

`py 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], Dict[int, Any], Dict[str, Any]]] = None, exclude: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) Dict[str, Any]#
Parameters:
Return type:

Dict[str, Any]

classmethod from_orm(obj: Any) Self#
Parameters:

obj (Any) –

Return type:

Self

json(*, include: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = None, exclude: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = 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:
Return type:

str

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) – The set of field names accepted for the Model instance.

  • values (Any) – Trusted or pre-validated data dictionary.

Returns:

A new instance of the Model class with validated data.

Return type:

Self

model_copy(*, update: dict[str, Any] | None = None, deep: bool = False) Self#

Usage docs: https://docs.pydantic.dev/2.8/concepts/serialization/#model_copy

Returns a copy of the model.

Parameters:
  • update (dict[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.

  • deep (bool) – Set to True to make a deep copy of the model.

Returns:

New model instance.

Return type:

Self

model_dump(*, mode: Union[Literal['json', 'python'], str] = 'python', include: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = None, exclude: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = 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.8/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], Dict[int, Any], Dict[str, Any]]]) – A set of fields to include in the output.

  • exclude (Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]]) – 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:

dict[str, Any]

model_dump_json(*, indent: int | None = None, include: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = None, exclude: Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]] = 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.8/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], Dict[int, Any], Dict[str, Any]]]) – Field(s) to include in the JSON output.

  • exclude (Optional[Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]]) – 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:

str

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:

dict[str, Any]

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:

str

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: dict[str, Any] | 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 (dict[str, Any] | 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:
  • obj (Any) – The object to validate.

  • strict (bool | None) – Whether to enforce types strictly.

  • from_attributes (bool | None) – Whether to extract data from object attributes.

  • context (Any | None) – Additional context to pass to the validator.

Raises:

ValidationError – If the object could not be validated.

Returns:

The validated model instance.

Return type:

Self

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.8/concepts/json/#json-parsing

Validate the given JSON data against the Pydantic model.

Parameters:
  • json_data (str | bytes | bytearray) – The JSON data to validate.

  • strict (bool | None) – Whether to enforce types strictly.

  • context (Any | None) – Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

Raises:

ValueError – If json_data is not a JSON string.

Return type:

Self

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.

Parameters:
  • obj (Any) – The object containing string data to validate.

  • strict (bool | None) – Whether to enforce types strictly.

  • context (Any | None) – Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

Return type:

Self

classmethod parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) Self#
Parameters:
  • path (str | Path) –

  • content_type (str | None) –

  • encoding (str) –

  • proto (DeprecatedParseProtocol | None) –

  • allow_pickle (bool) –

Return type:

Self

classmethod parse_obj(obj: Any) Self#
Parameters:

obj (Any) –

Return type:

Self

classmethod parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) Self#
Parameters:
  • b (str | bytes) –

  • content_type (str | None) –

  • encoding (str) –

  • proto (DeprecatedParseProtocol | None) –

  • allow_pickle (bool) –

Return type:

Self

classmethod schema(by_alias: bool = True, ref_template: str = '#/$defs/{model}') Dict[str, Any]#
Parameters:
  • by_alias (bool) –

  • ref_template (str) –

Return type:

Dict[str, Any]

classmethod schema_json(*, by_alias: bool = True, ref_template: str = '#/$defs/{model}', **dumps_kwargs: Any) str#
Parameters:
  • by_alias (bool) –

  • ref_template (str) –

  • dumps_kwargs (Any) –

Return type:

str

classmethod update_forward_refs(**localns: Any) None#
Parameters:

localns (Any) –

Return type:

None

classmethod validate(value: Any) Self#
Parameters:

value (Any) –

Return type:

Self

always_apply: bool | None#

Data descriptor used to emit a runtime deprecation warning before accessing a deprecated field.

msg#

The deprecation message to be emitted.

wrapped_property#

The property instance if the deprecated field is a computed field, or None.

field_name#

The name of the field being deprecated.

property model_extra: dict[str, Any] | None#

Get extra fields set during validation.

Returns:

A dictionary of extra fields, or None if config.extra is not set to “allow”.

property model_fields_set: set[str]#

Returns the set of fields that have been explicitly set on this model instance.

Returns:

A set of strings representing the fields that have been set,

i.e. that were not filled from defaults.

__init__(min_val=0.0, max_val=1.0, dtype=5, always_apply=False, 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(image, **params)[source]#

Apply transform on image.

apply_to_images(images: ndarray, **params: Any) list[numpy.ndarray]#

Apply transform on images.

Parameters:
Return type:

list[numpy.ndarray]

apply_with_params(params: dict[str, Any], *args: Any, **kwargs: Any) dict[str, Any]#

Apply transforms with parameters.

Parameters:
Return type:

dict[str, Any]

get_base_init_args() dict[str, Any]#

Returns base init args - p

Return type:

dict[str, Any]

classmethod get_class_fullname() str#
Return type:

str

get_dict_with_id() dict[str, Any]#
Return type:

dict[str, Any]

get_params() dict[str, Any]#

Returns parameters independent of input.

Return type:

dict[str, Any]

get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#

Returns parameters dependent on input.

Parameters:
Return type:

dict[str, Any]

get_params_dependent_on_targets(params: dict[str, Any]) dict[str, Any]#

This method is deprecated. Use get_params_dependent_on_data instead. Returns parameters dependent on targets. Dependent target is defined in self.targets_as_params

Parameters:

params (dict[str, Any]) –

Return type:

dict[str, Any]

get_transform_init_args() dict[str, Any]#
Return type:

dict[str, Any]

get_transform_init_args_names()[source]#

Returns names of arguments that are used in __init__ method of the transform.

classmethod is_serializable() bool#
Return type:

bool

set_deterministic(flag: bool, save_key: str = 'replay') BasicTransform#

Set transform to be deterministic.

Parameters:
  • flag (bool) –

  • save_key (str) –

Return type:

BasicTransform

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:

dict[str, Any]

to_dict_private() dict[str, Any]#
Return type:

dict[str, Any]

update_params(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.

Parameters:
Return type:

dict[str, Any]

update_params_shape(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#

Updates parameters with input image shape.

Parameters:
Return type:

dict[str, Any]

applied_in_replay = False#
property available_keys: set[str]#

Returns set of available keys.

call_backup = None#
deterministic: bool = False#
fill_value: ColorType#
interpolation: int#
mask_fill_value: ColorType | None#
replay_mode = False#
save_key = 'replay'#
property targets: dict[str, Callable[..., Any]]#
property targets_as_params: list[str]#

Targets used to get params dependent on targets. This is used to check input has all required targets.