solt.utils module
- 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'>, 'random_resized_crop': <class 'solt.transforms._transforms.RandomResizedCrop'>, '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:
- 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:
- 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:
- 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.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:
- 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:
- solt.utils.img_shape_checker(method)[source]
Decorator to ensure that the image has always 3 dimensions: WxHC
- Parameters:
method (_apply_img method of BaseTransform)
- Returns:
out – Result
- Return type:
method of a class
- 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:
- 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:
- Returns:
out – New parameter value wrapped into a tuple.
- Return type: