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, 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.
Returns base init args - p
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.
Returns names of arguments that are used in __init__ method of the transform.
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.
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:
BaseTransformInitSchemaShow 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
- 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]#
- 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:
- 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.
- 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.
- 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:
- 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:
- 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: 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:
- 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.8/concepts/json/#json-parsing
Validate the given JSON data against the Pydantic model.
- Parameters:
- Returns:
The validated Pydantic model.
- Raises:
ValueError – If json_data is not a JSON string.
- 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#
- 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.
- __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_to_images(images: ndarray, **params: Any) list[numpy.ndarray]#
Apply transform on images.
- Parameters:
- Return type:
- apply_with_params(params: dict[str, Any], *args: Any, **kwargs: Any) dict[str, Any]#
Apply transforms with parameters.
- get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#
Returns parameters dependent on input.
- 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
- 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.
- 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:
- 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.
- update_params_shape(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]#
Updates parameters with input image shape.
- applied_in_replay = False#
- call_backup = None#
- fill_value: ColorType#
- replay_mode = False#
- save_key = 'replay'#