class solt.core.Stream(transforms=None, interpolation=None, padding=None, optimize_stack=False, ignore_fast_mode=False)[source]

Bases: solt.utils._serial.Serializable

Stream class. Executes the list of transformations

  • transforms (list or None) – List of transforms to execute
  • interpolation (str or None) – Stream-wide settings for interpolation. If for some particular transform your would like to still use its own mode, simply pass (<interpolation_value>, 'strict') in the constructor of that transform.
  • padding (str or None) – Stream-wide settings for padding. If for some particular transform your would like to still use its own mode, simply pass (<padding_value>, 'strict') in the constructor of that transform.
  • optimize_stack (bool) – Whether to run transforms stack optimization. It can only be useful if many matrix transformations are in a row.
  • ignore_fast_mode (bool) – Whether to ignore the fast mode. This option enables full geometric transforms.
static exec_stream(transforms, data, optimize_stack)[source]

Static method, executes the list of transformations for a given data point.

  • transforms (list) – List of transformations to execute
  • data (DataContainer or dict) – Data to be augmented. See to check how a conversion from dict is done.
  • optimize_stack (bool) – Whether to execute augmentations stack optimization.

out – Result

Return type:


static optimize_transforms_stack(transforms, data)[source]

Static method which fuses the transformations

  • transforms (list) – A list of transforms
  • data (DataContainer) – Data container to be used to sample the transforms

out – An optimized list of transforms

Return type:



Resets the interpolation for the whole pipeline of transforms.

Parameters:value (str or None) – A value from solt.constants.ALLOWED_INTERPOLATIONS

See also



Allows to reset the padding for the whole Stream

Parameters:value (str) – Should be a string from solt.constants.ALLOWED_PADDINGS

See also


serializable_name = 'stream'

How the class should be stored in the registry

class solt.core.SelectiveStream(transforms=None, n=1, probs=None, optimize_stack=False, ignore_fast_mode=False)[source]

Bases: solt.core._core.Stream

Stream that uniformly selects n out of k given transforms.

serializable_name = 'selective_stream'

How the class should be stored in the registry

class solt.core.DataContainer(data, fmt, transform_settings=None)[source]

Bases: object

Data container to encapsulate different types of data, such as images, bounding boxes, etc.

The container itself is iterable according to the format.

  • data (tuple) – Data items stored in a tuple
  • fmt (str) – Data format. Example: ‘IMMM’ - image and three masks.
  • transform_settings (dict or None) – Settings for each data item. At this stage, the settings include only padding and interpolation. The key in this dict corresponds to the index of the element in the given data tuple. The value is another dict, which has all the settings. Segmentation masks have nearest neighbor interpolation by default, this can be changed manually if needed. Example: transform_settings={0:{'interpolation':'bilinear'}, 1: {'interpolation':'bicubic'}}
static from_dict(data)[source]

Creates a data container from a dictionary.

If data is a dict, then the will be created so that the image data will be stored first. Subsequently, multiple images under the key images will be stored. The same applies to masks (first mask and then masks), labels (label and labels), and the keypoints (keypoints and keypoints_array). You must use object here. Labels will always be stored last.

For example, if the input dict looks like this: d = {'label': l1, 'image': i1, 'mask': m1} or d = {'mask': m1, 'image': i1, 'label': l1}, the DataContainer will convert this into sld.DataContainer((i1, m1, l1), 'IML').

More complex case:

d = {'image': i1, masks: (m1, m2, m3, m4), 'labels': (l1, l2, l3, l4, l5),
'keypoints': solt.core.KeyPoints(k, h, w)
dc_from_dict = solt.core.DataContainer.from_dict(d)

will be equivalent to

dc = solt.core.DataContainer((i1, m1, m2, m3, m4, solt.core.KeyPoints(k, h, w), l1, l2, l3, l4, l5),

Please note, that when you create DataContainer using such a simplified interface, you cannot setup the transform parameters per item. Use a proper constructor instead.

Parameters:data (dict) – Data stored in a dictionary
Returns:out – Newly instantiated data container object
Return type:sld.DataContainer
to_torch(as_dict=False, scale_keypoints=True, normalize=False, mean=None, std=None)[source]

This method converts the DataContainer Content into a dict or a list PyTorch objects

  • as_dict (bool) – Whether to return the result as a dictionary. If a single item is present, then the singular naming will be used. If plural, then the plural will be used. The items will be stored and sorted a similar manner to the method from_dict: images, masks, keypoints_array, and labels. The same applies to a singular case.
  • scale_keypoints (bool) – Whether to scale keypoints to 0-1 range. True by default.
  • normalize (bool) – Whether to subtract the mean and divide by the std.
  • mean (torch.Tensor) – Mean to subtract. If None, then the ImageNet mean will be subtracted.
  • std (torch.Tensor) – Std to subtract. If None, then the ImageNet std will be subtracted.

Validates frame consistency in the wrapped data.

class solt.core.Keypoints(pts=None, frame=None)[source]

Bases: object

Keypoints class

  • pts (numpy.ndarray) – Array of keypoints. If 2D, has to be in (x, y) format.
  • frame ((n, ) list-like of ints) – Shape of the coordinate frame. frame[0] is height, frame[1] is width.
class solt.core.BaseTransform(p=None, data_indices=None)[source]

Bases: solt.utils._serial.Serializable

Transformation abstract class.

  • p (float or None) – Probability of executing this transform
  • data_indices (tuple or None) – Indices where the transforms need to be applied
apply(data: solt.core._data.DataContainer)[source]

Applies transformation to a DataContainer items depending on the type.

Parameters:data (DataContainer) – Data to be augmented
Returns:out – Result
Return type:DataContainer
sample_transform(data: solt.core._data.DataContainer)[source]

Validates data and samples transform parameters based on it.

Parameters:data (DataContainer) – Data container to be used for sampling.
Returns:out – Coordinate frame (d0, d1, …). (d0, d1) are (height, width), respectively.
Return type:tuple

Method to randomly determine whether to use this transform.

Returns:out – Boolean flag. True if the transform is used.
Return type:bool
class solt.core.MatrixTransform(interpolation='bilinear', padding='z', p=0.5, ignore_state=True, affine=True, ignore_fast_mode=False)[source]

Bases: solt.core._base_transforms.BaseTransform, solt.core._base_transforms.InterpolationPropertyHolder, solt.core._base_transforms.PaddingPropertyHolder

Matrix Transform abstract class. (Affine and Homography). Does all the transforms around the image / center.

  • interpolation (str) – Interpolation mode.
  • padding (str or None) – Padding Mode.
  • p (float) – Probability of transform’s execution.
  • ignore_state (bool) – Whether to ignore the pre-calculated transformation or not. If False, then it will lead to an incorrect behavior when the objects are of different sizes. Should be used only when it is assumed that the image, mask and keypoints are of the same size.
static correct_for_frame_change(transform_matrix: numpy.ndarray, width: int, height: int)[source]

Method takes a matrix transform, and modifies its origin.

  • transform_matrix (numpy.ndarray) – Transform (3x3) matrix
  • width (int) – Width of the coordinate frame
  • height (int) – Height of the coordinate frame

out – Modified Transform matrix

Return type:



Takes a transform an performs a matrix fusion. This is useful to optimize the computations

Parameters:trf (MatrixTransform) –

Samples the transform and corrects for frame change.

Return type:None

Method that is called to sample the transform matrix

class solt.core.PaddingPropertyHolder(padding=None)[source]

Bases: object

Adds padding property to a class and validates it using the allowed paddings from constants.

Parameters:padding (None or str or tuple) – Padding mode. Inheritance can be specified as the second argument of the padding tuple.
class solt.core.InterpolationPropertyHolder(interpolation=None)[source]

Bases: object

Adds interpolation property to a class and validates it using the allowed interpolations from constants.

Parameters:interpolation (None or str or tuple) – Interpolation mode. Inheritance can be specified as the second argument of the interpolation tuple.
class solt.core.ImageTransform(p=None, data_indices=None)[source]

Bases: solt.core._base_transforms.BaseTransform

Abstract class, allowing the application of a transform only to an image