Skip to content

Serialization API (core.serialization)

class albumentations.core.serialization.Serializable [view source on GitHub]

albumentations.core.serialization.Serializable.to_dict (self, on_not_implemented_error='raise')

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:

Name Type Description
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.

class albumentations.core.serialization.SerializableMeta [view source on GitHub]

A metaclass that is used to register classes in SERIALIZABLE_REGISTRY or NON_SERIALIZABLE_REGISTRY so they can be found later while deserializing transformation pipeline using classes full names.

albumentations.core.serialization.SerializableMeta.__new__ (mcs, name, bases, *args, **kwargs) special staticmethod

Create and return a new object. See help(type) for accurate signature.

def albumentations.core.serialization.from_dict (transform_dict, nonserializable=None, lambda_transforms='deprecated') [view source on GitHub]

Parameters:

Name Type Description
transform_dict Dict[str, Any]

A dictionary with serialized transform pipeline.

nonserializable Optional[Dict[str, Any]]

A dictionary that contains non-serializable transforms. This dictionary is required when you are restoring a pipeline that contains non-serializable transforms. Keys in that dictionary should be named same as name arguments in respective transforms from a serialized pipeline.

lambda_transforms Union[Dict[str, Any], NoneType, str]

Deprecated. Use 'nonserizalizable' instead.

def albumentations.core.serialization.load (filepath, data_format='json', nonserializable=None, lambda_transforms='deprecated') [view source on GitHub]

Load a serialized pipeline from a json or yaml file and construct a transform pipeline.

Parameters:

Name Type Description
filepath str

Filepath to read from.

data_format str

Serialization format. Should be either json or 'yaml'.

nonserializable Optional[Dict[str, Any]]

A dictionary that contains non-serializable transforms. This dictionary is required when you are restoring a pipeline that contains non-serializable transforms. Keys in that dictionary should be named same as name arguments in respective transforms from a serialized pipeline.

lambda_transforms Union[Dict[str, Any], NoneType, str]

Deprecated. Use 'nonserizalizable' instead.

def albumentations.core.serialization.register_additional_transforms () [view source on GitHub]

Register transforms that are not imported directly into the albumentations module.

def albumentations.core.serialization.save (transform, filepath, data_format='json', on_not_implemented_error='raise') [view source on GitHub]

Take a transform pipeline, serialize it and save a serialized version to a file using either json or yaml format.

Parameters:

Name Type Description
transform Serializable

Transform to serialize.

filepath str

Filepath to write to.

data_format str

Serialization format. Should be either json or 'yaml'.

on_not_implemented_error str

Parameter that describes what to do if a transform doesn't implement the to_dict method. If 'raise' then NotImplementedError is raised, if warn then the exception will be ignored and no transform arguments will be saved.

def albumentations.core.serialization.to_dict (transform, on_not_implemented_error='raise') [view source on GitHub]

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:

Name Type Description
transform Serializable

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.