solt.utils module

solt.utils.from_dict(transforms)[source]
Deserializes the transformations stored in a dict.
Supports deserialization of Streams only.
Parameters:transforms (dict) – Transforms
Returns:out – An instance of solt.core.Stream.
Return type:solt.core.Stream
solt.utils.from_json(s)[source]

Allows to deserialize transforms from a json file.

Parameters:s (str or pathlib.Path) – Json string or path. Path can be stored as a string or as a pathlib object.
Returns:s – A serializable object
Return type:Serializable
solt.utils.from_yaml(s)[source]

Allows to deserialize transforms from a yaml file.

Parameters:s (str or pathlib.Path) – Path to the yaml object.
Returns:s – A serializable object
Return type:Serializable
class solt.utils.Serializable[source]

Bases: object

registry = {'blur': <class 'solt.transforms._transforms.Blur'>, 'brightness': <class 'solt.transforms._transforms.Brightness'>, 'contrast': <class 'solt.transforms._transforms.Contrast'>, 'crop': <class 'solt.transforms._transforms.Crop'>, 'cutout': <class 'solt.transforms._transforms.CutOut'>, 'cvt_color': <class 'solt.transforms._transforms.CvtColor'>, 'flip': <class 'solt.transforms._transforms.Flip'>, 'gamma_correction': <class 'solt.transforms._transforms.GammaCorrection'>, 'gridmask': <class 'solt.transforms._transforms.GridMask'>, 'hsv': <class 'solt.transforms._transforms.HSV'>, 'intensity_remap': <class 'solt.transforms._transforms.IntensityRemap'>, 'jpeg_compression': <class 'solt.transforms._transforms.JPEGCompression'>, 'keypoints_jitter': <class 'solt.transforms._transforms.KeypointsJitter'>, 'noise': <class 'solt.transforms._transforms.Noise'>, 'pad': <class 'solt.transforms._transforms.Pad'>, 'projection': <class 'solt.transforms._transforms.Projection'>, 'resize': <class 'solt.transforms._transforms.Resize'>, 'rotate': <class 'solt.transforms._transforms.Rotate'>, 'rotate_90': <class 'solt.transforms._transforms.Rotate90'>, 'salt_and_pepper': <class 'solt.transforms._transforms.SaltAndPepper'>, 'scale': <class 'solt.transforms._transforms.Scale'>, 'selective_stream': <class 'solt.core._core.SelectiveStream'>, 'shear': <class 'solt.transforms._transforms.Shear'>, 'stream': <class 'solt.core._core.Stream'>, 'translate': <class 'solt.transforms._transforms.Translate'>}
serializable_name = None

How the class should be stored in the registry. If None (default), the transform is not added.

to_dict()[source]

Method returns a dict, describing the object sufficiently enough to reconstruct it back.

Returns:out – OrderedDict, ready for json serialization.
Return type:dict
to_json(filename=None)[source]

Writes a Serializable object into a json file. If the filename is None, then this function returns a string.

Parameters:filename (str or pathlib.Path or None) –
Returns:out – Serialized object
Return type:str
to_yaml(filename=None)[source]

Writes a Serializable object into a file. If the filename is None, then this function just returns a string.

Parameters:filename (str or pathlib.Path or None) – Path to the .yaml file.
Returns:out – Serialized object
Return type:str
solt.utils.ensure_valid_image(num_dims_total=None, num_dims_spatial=None, num_channels=None, keep_num_dims=True)[source]
Parameters:
  • num_dims_total (tuple of ints or None) – If not None, checks whether the number of the input dimensions is among the specified values.
  • num_dims_spatial (tuple of ints or None) – If not None, checks whether the number of the spatial (i.e. total - 1) dimensions is among the specified values.
  • num_channels (tuple of ints or None) – If not None, checks whether the shape of the last dimension is among the specified values.
  • keep_num_dims (bool) – If True, adds the trailing dimensions to the result to match the input.
Raises:

ValueError: – If one or several of the checks failed.

solt.utils.validate_numeric_range_parameter(parameter, default_val, min_val=None, max_val=None)[source]

Validates the range-type parameter, e.g. angle in Random Rotation.

Parameters:
  • parameter (tuple or None) – The value of the parameter
  • default_val (object) – Default value of the parameter if it is None.
  • min_val (None or float or int) – Check whether the parameter is greater or equal than this. Optional.
  • max_val (None or float or int) – Check whether the parameter is less or equal than this. Optional.
Returns:

out – Parameter value, passed all the checks.

Return type:

tuple

solt.utils.validate_parameter(parameter, allowed_modes, default_value, basic_type=<class 'str'>, heritable=True)[source]

Validates the parameter and wraps it into a tuple with the inheritance option (if parameter is not a tuple already). In this case the parameter will become a tuple (parameter, ‘inherit’), which will indicate that the stream settings will override this parameter. In case if the parameter is already a tuple specified as parameter=(value, ‘strict’), then the parameter will not be overrided.

Parameters:
  • parameter (object) – The value of the parameter
  • allowed_modes (dict or set) – Allowed values for the parameter
  • default_value (object) – Default value to substitute if the parameter is None
  • basic_type (type) – Type of the parameter.
  • heritable (bool) – Whether to check for heretability option.
Returns:

out – New parameter value wrapped into a tuple.

Return type:

tuple