minerva.transforms

Submodules

Classes

CastTo

Cast the input data to the specified data type.

ColorJitter

This class is a base class for all transforms. Transforms is just a

ContrastiveTransform

This class is a base class for all transforms. Transforms is just a

Crop

Crop an image to a given output size, with optional padding and bounding-box support.

Flip

Flip the input data along the specified axis.

Gradient

This class is a base class for all transforms. Transforms is just a

GrayScale

This class is a base class for all transforms. Transforms is just a

Identity

This class is a dummy transform that does nothing. It is useful when

Indexer

This class is a base class for all transforms. Transforms is just a

Normalize

This class is a base class for all transforms. Transforms is just a

PadCrop

This class is a base class for all transforms. Transforms is just a

Padding

This class is a base class for all transforms. Transforms is just a

PerlinMasker

Zeroes entries of a tensor according to the sign of Perlin noise. Seed for the noise generator given by torch.randint

RandomCrop

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

RandomFlip

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

RandomGrayScale

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

RandomRotation

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

RandomSolarize

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

Repeat

This class is a base class for all transforms. Transforms is just a

Rotation

This class is a base class for all transforms. Transforms is just a

Solarize

This class is a base class for all transforms. Transforms is just a

Squeeze

Remove single-dimensional entries from the shape of an array.

TransformPipeline

Apply a sequence of transforms to a single sample of data and return the

Transpose

Reorder the axes of numpy arrays.

Unsqueeze

Add a new axis to the input data at the specified position.

_RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

_Transform

This class is a base class for all transforms. Transforms is just a

Package Contents

class minerva.transforms.CastTo(dtype)[source]

Bases: _Transform

Cast the input data to the specified data type.

Cast the input data to the specified data type.

Parameters

dtypetype

The data type to which the input data will be cast.

__call__(x)[source]

Cast the input data to the specified data type.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

dtype
Parameters:

dtype (Union[type, str])

class minerva.transforms.ColorJitter(brightness=1.0, contrast=1.0, saturation=1.0, hue=0.0)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Applies fixed adjustments to brightness, contrast, saturation, and hue to an input image.

Parameters

brightnessfloat, optional

Fixed factor for brightness adjustment. A value of 1.0 means no change. Defaults to 1.0.

contrastfloat, optional

Fixed factor for contrast adjustment. A value of 1.0 means no change. Defaults to 1.0.

saturationfloat, optional

Fixed factor for saturation adjustment. A value of 1.0 means no change. Defaults to 1.0.

huefloat, optional

Fixed degree shift for hue adjustment, in the range [-180, 180]. Defaults to 0.0.

Returns

np.ndarray

The transformed image with fixed brightness, contrast, saturation, and hue adjustments applied.

__call__(image)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

image (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

brightness = 1.0
contrast = 1.0
hue = 0.0
saturation = 1.0
Parameters:
  • brightness (float)

  • contrast (float)

  • saturation (float)

  • hue (float)

class minerva.transforms.ContrastiveTransform(transform)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

A transformation wrapper that applies the same transform twice to create contrastive pairs.

This transform is commonly used in contrastive learning approaches where you need two different augmented versions of the same input. It takes a base transformation and applies it twice independently to the same input, potentially producing different results if the underlying transform includes randomness.

Parameters

transform_Transform

The base transformation to be applied twice. This should be a callable that takes a numpy array and returns a transformed numpy array.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

Tuple

__str__()[source]
Return type:

str

transform
Parameters:

transform (_Transform)

class minerva.transforms.Crop(output_size, pad_mode='reflect', coords=(0, 0), bbox=None)[source]

Bases: _Transform

Crop an image to a given output size, with optional padding and bounding-box support.

Expects inputs in CHW (C, H, W) or 2D (H, W) format.

Parameters

output_sizeTuple[int, int]

Desired output size as (height, width).

pad_modestr, optional

Padding mode used if output size is larger than input size. Defaults to ‘reflect’. Valid modes include: ‘constant’, ‘edge’, ‘linear_ramp’, ‘maximum’, ‘mean’, ‘median’, ‘minimum’, ‘reflect’, ‘symmetric’, ‘wrap’, ‘empty’.

coordsTuple[float, float], optional

Top-left coordinates for the crop box as (row, col). Values must go from 0 to 1 indicating the relative position on where the new top-left corner can be set, taking in consideration the new size. Defaults to (0, 0) which corresponds to the top-left corner of the image.

bboxOptional[Tuple[int, int, int, int]], optional

If provided, crops the image to the bounding box defined by (y1, y2, x1, x2). If this parameter is set, the coords parameter is ignored. Defaults to None.

__call__(image)[source]

Crop the image to the configured output size.

Parameters

imagenp.ndarray

Input array in CHW (C, H, W) or 2D (H, W) format.

Returns

np.ndarray

Cropped array. Shape is (C, new_h, new_w) for 3D input or (new_h, new_w) for 2D input. Padded symmetrically if the output size exceeds the input size.

Parameters:

image (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

bbox = None
coords = (0, 0)
output_size
pad_mode = 'reflect'
Parameters:
  • output_size (Tuple[int, int])

  • pad_mode (str)

  • coords (Tuple[float, float])

  • bbox (Optional[Tuple[int, int, int, int]])

class minerva.transforms.Flip(axis=1)[source]

Bases: _Transform

Flip the input data along the specified axis.

Flip the input data along the specified axis.

Parameters

axisint | List[int], optional

One or more axis to flip the input data along, by default 1 (horizontal). If a list of axis is provided, the input data is flipped along all the specified axis in the order they are provided.

__call__(x)[source]

Flip the input data along the specified axis. if axis is an integer, the input data is flipped along the specified axis. if axis is a list of integers, the input data is flipped along all the specified axis in the order they are provided. The input must have the same, or less, number of dimensions as the length of the list of axis.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

axis = 1
Parameters:

axis (Union[int, List[int]])

class minerva.transforms.Gradient(direction)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

direction:

0 -> Gradient along the x-axis (width) 1 -> Gradient along the y-axis (height)

Parameters:

direction (int)

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

__str__()[source]
Return type:

str

direction
directions
generate_gradient(shape)[source]

Inputs in format (H, W) Outputs a gradient from 0 to 1 in either x or y direction based on the direction parameter

Parameters:

shape (tuple[int, int])

Return type:

numpy.ndarray

class minerva.transforms.GrayScale(method='luminosity')[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Converts an image to grayscale using the specified method.

Parameters

method{‘average’, ‘luminosity’}, optional

The method to compute grayscale: - ‘average’: (R + G + B) / 3 - ‘luminosity’: 0.299R + 0.587G + 0.114B Defaults to ‘luminosity’.

__call__(image)[source]

Applies grayscale conversion to the input RGB image.

Parameters

imagenp.ndarray

Input image in RGB format with shape (H, W, 3).

Returns

np.ndarray

Grayscale image with shape (H, W, 3) where all channels are equal.

Parameters:

image (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

method = 'luminosity'
Parameters:

method (Literal['average', 'luminosity'])

class minerva.transforms.Identity[source]

Bases: _Transform

This class is a dummy transform that does nothing. It is useful when you want to skip a transform in a pipeline.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

class minerva.transforms.Indexer(index)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

This transform extracts a single channel from a multi-channel image.

Parameters

indexint

The index of the channel to extract.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

index
Parameters:

index (int)

class minerva.transforms.Normalize(mean, std, to_rgb=False, normalize_labels=False)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Normalize the input data using the provided means and standard deviations. I assumes the data shape is (C, H, W)

Parameters

meanList[float]

List of means for each channel.

stdList[float]

List of standard deviations for each channel.

to_rgbbool, optional

Convert grayscale images to RGB format, by default False.

normalize_labelsbool, optional

Normalize label images, by default False.

__call__(data)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

__str__()[source]
Return type:

str

mean
normalize_labels = False
std
to_rgb = False
class minerva.transforms.PadCrop(target_h_size, target_w_size, padding_mode='reflect', seed=None, constant_values=0)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Transforms image and pads or crops it to the target size. If the target size is larger than the input size, the image is padded, else, the image is cropped. The same happens for both height and width. The padding mode can be specified, as well as the seed for the random number generator.

For padding, the padding is applied symmetrically on both sides of the image, thus, image will be centered in the padded image. For cropping, the crop is applied from a random position in the image.

Image is expected to be in C x H x W, or H x W format.

Parameters

target_h_sizeint

Desired height size.

target_w_sizeint

Desired width size.

padding_modestr, optional

The padding mode to use, by default “reflect”

seedint, optional

The seed for the random number generator. It is used to generate the random crop position. By default, None.

constant_valuesint, optional

If padding mode is ‘constant’, the value to use for padding. By default 0.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

constant_values = 0
padding_mode = 'reflect'
rng
seed = None
target_h_size
target_w_size
Parameters:
  • target_h_size (int)

  • target_w_size (int)

  • padding_mode (str)

  • seed (Optional[int])

  • constant_values (int)

class minerva.transforms.Padding(target_h_size, target_w_size, padding_mode='reflect', padding_value=0, mask_padding_value=255)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

A transform that pads images and masks to reach target dimensions.

This transform automatically pads input arrays to the specified target dimensions using different padding strategies. It intelligently determines whether the input is an image or mask based on the data type and applies appropriate padding values. For unsigned integer arrays (typically masks), it uses the mask padding value, while for other arrays (typically images), it uses the regular padding value.

Parameters

target_h_sizeint

Target height in pixels after padding.

target_w_sizeint

Target width in pixels after padding.

padding_modestr, default=”reflect”

Padding mode to use. Options include “reflect”, “constant”, “edge”, “wrap”. When using “constant”, the padding values specified below will be used.

padding_valueint, default=0

Padding value to use for image data when padding_mode is “constant”. Only used for non-unsigned integer arrays.

mask_padding_valueint, default=255

Padding value to use for mask data when padding_mode is “constant”. Only used for unsigned integer arrays. Commonly set to 255 to represent ignore class in segmentation masks.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

mask_padding_value = 255
padding_mode = 'reflect'
padding_value = 0
target_h_size
target_w_size
Parameters:
  • target_h_size (int)

  • target_w_size (int)

  • padding_mode (str)

  • padding_value (int)

  • mask_padding_value (int)

class minerva.transforms.PerlinMasker(octaves, scale=1)[source]

Bases: _Transform

Zeroes entries of a tensor according to the sign of Perlin noise. Seed for the noise generator given by torch.randint

Zeroes entries of a tensor according to the sign of Perlin noise. Seed for the noise generator given by torch.randint

Parameters

octaves: int

Level of detail for the Perlin noise generator

scale: float = 1

Optionally rescale the Perlin noise. Default is 1 (no rescaling)

__call__(x)[source]

Zeroes entries of a tensor according to the sign of Perlin noise.

Parameters

x: np.ndarray

The tensor whose entries to zero.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

octaves
scale = 1
Parameters:
  • octaves (int)

  • scale (float)

class minerva.transforms.RandomCrop(crop_size, num_samples=1, seed=None, pad_mode='reflect')[source]

Bases: _RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

A random cropping transform that applies the same random crop to multiple data items.

This transform randomly selects crop coordinates and applies the same crop operation to multiple data items that need to be processed together, ensuring consistency across related data (e.g., image-mask pairs, multiple images with shared labels, etc.). If the crop extends beyond image boundaries, padding is applied using the specified mode. The random crop coordinates are generated once and reused across all data items in the group.

Parameters

crop_sizeTuple[int, int]

The desired output size for the crop as (height, width) in pixels.

num_samplesint, default=1

The number of times the same random crop transformation will be applied when called. Set to 2 for data-label pairs, 3 or more for datasets with multiple related items, or 1 for single data items or contrastive learning scenarios.

seedOptional[int], default=None

Random seed for reproducible crop selection. If None, uses system randomness.

pad_modestr, default=”reflect”

Padding mode to use when crop extends beyond image boundaries. Common modes include “reflect”, “constant”, “edge”, “wrap”.

__str__()[source]
Return type:

str

crop_size
pad_mode = 'reflect'
select_transform()[source]
Parameters:
  • crop_size (Tuple[int, int])

  • num_samples (int)

  • seed (Optional[int])

  • pad_mode (str)

class minerva.transforms.RandomFlip(num_samples=1, possible_axis=1, prob=0.5, seed=None)[source]

Bases: _RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

A transform that flips the input data along a random axis.

Parameters

num_samplesint

The number of samples that will be transformed.

possible_axisUnion[int, List[int]], optional

Possible axis to be transformed, will be chosen at random, by default 0

probfloat, optional

Probability of applying the transform, by default 0.5

seedOptional[int], optional

A seed to ensure deterministic run, by default None

__str__()[source]
Return type:

str

possible_axis = 1
prob = 0.5
select_transform()[source]

selects the transform to be applied to the data.

Parameters:
  • num_samples (int)

  • possible_axis (Union[int, List[int]])

  • prob (float)

  • seed (Optional[int])

class minerva.transforms.RandomGrayScale(num_samples=1, seed=None, prob=0.1, method='luminosity')[source]

Bases: _RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

A random grayscale conversion transform that applies the same grayscale operation to multiple data items.

This transform randomly decides whether to convert images to grayscale based on a specified probability. When activated, it applies the same grayscale conversion to all related data items, ensuring consistency. The transform uses different methods for grayscale conversion and can be controlled by probability to create data augmentation effects.

Parameters

num_samplesint, default=1

The number of times the same random grayscale transformation will be applied when called. Set to 2 for data-label pairs, 3 or more for datasets with multiple related items, or 1 for single data items or contrastive learning scenarios.

seedOptional[int], default=None

Random seed for reproducible grayscale selection. If None, uses system randomness.

probfloat, default=0.1

Probability of applying the grayscale transformation. Must be between 0.0 and 1.0. Higher values make grayscale conversion more likely.

methodLiteral[“average”, “luminosity”], default=”luminosity”

Method for grayscale conversion. “average” computes simple mean of RGB channels, “luminosity” uses weighted average based on human perception of brightness.

__str__()[source]
Return type:

str

method = 'luminosity'
prob = 0.1
select_transform()[source]
Parameters:
  • num_samples (int)

  • seed (Optional[int])

  • prob (float)

  • method (Literal['average', 'luminosity'])

class minerva.transforms.RandomRotation(degrees, prob, num_samples=1, seed=None)[source]

Bases: _RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

A random rotation transform that applies the same rotation to multiple data items.

This transform randomly decides whether to apply rotation based on a specified probability. When activated, it samples a rotation angle uniformly from the specified range and applies the same rotation to all related data items, ensuring consistency across image-mask pairs or other related data.

Parameters

degreesfloat

Maximum absolute value of the rotation angle in degrees. The angle is sampled uniformly from [-degrees, +degrees].

probfloat

Probability of applying the rotation transformation. Must be between 0.0 and 1.0. Higher values make rotation more likely.

num_samplesint, default=1

The number of times the same random rotation transformation will be applied when called. Set to 2 for data-label pairs, 3 or more for datasets with multiple related items, or 1 for single data items or contrastive learning scenarios.

seedOptional[int], default=None

Random seed for reproducible rotation selection and angle generation. If None, uses system randomness.

__str__()[source]
Return type:

str

degrees
prob
select_transform()[source]
Parameters:
  • degrees (float)

  • prob (float)

  • num_samples (int)

  • seed (Optional[int])

class minerva.transforms.RandomSolarize(num_samples=1, seed=None, threshold=128, prob=1.0)[source]

Bases: _RandomSyncedTransform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

A random solarization transform that applies the same solarize operation to multiple data items.

This transform randomly decides whether to apply solarization based on a specified probability. Solarization inverts pixel values above a given threshold, creating a photographic negative effect for bright regions while keeping darker regions unchanged. When activated, it applies the same solarization parameters to all related data items, ensuring consistency.

Parameters

num_samplesint, default=1

The number of times the same random solarize transformation will be applied when called. Set to 2 for data-label pairs, 3 or more for datasets with multiple related items, or 1 for single data items or contrastive learning scenarios.

seedOptional[int], default=None

Random seed for reproducible solarization selection. If None, uses system randomness.

thresholdint, default=128

Pixel intensity threshold for solarization. Pixels with values above this threshold will be inverted. Valid range is typically 0-255 for 8-bit images.

probfloat, default=1.0

Probability of applying the solarization transformation. Must be between 0.0 and 1.0. Higher values make solarization more likely.

__str__()[source]
Return type:

str

prob = 1.0
select_transform()[source]
threshold = 128
Parameters:
  • num_samples (int)

  • seed (Optional[int])

  • threshold (int)

  • prob (float)

class minerva.transforms.Repeat(axis, n_repetitions)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

This transform repeats the input data along the specified axis.

Parameters

axisint

The axis along which to repeat the input data.

n_repetitionsint

The number of repetitions.

__call__(x)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

axis
n_repetitions
Parameters:
  • axis (int)

  • n_repetitions (int)

class minerva.transforms.Rotation(degrees)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Rotates an image by a specified angle using reflection padding.

Parameters

degreesfloat

Angle in degrees to rotate the image counterclockwise.

Notes

  • Accepts input with shape (H, W) or (H, W, C), where C can be any number of channels.

  • For multi-channel images, the same transformation is applied to all channels.

  • Uses OpenCV’s warpAffine with reflection padding.

__call__(image)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

image (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

degrees
Parameters:

degrees (float)

class minerva.transforms.Solarize(threshold=128)[source]

Bases: _Transform

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

Solarizes the image by inverting pixel values above a specified threshold.

Parameters

thresholdint, optional

Intensity threshold for inversion, default is 128.

Returns

np.ndarray

Solarized image with inverted pixel values above threshold.

__call__(image)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Parameters:

image (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
threshold = 128
Parameters:

threshold (int)

class minerva.transforms.Squeeze(axis)[source]

Bases: _Transform

Remove single-dimensional entries from the shape of an array.

Remove single-dimensional entries from the shape of an array.

Parameters

axisint

The position of the axis to be removed.

__call__(x)[source]

Remove single-dimensional entries from the shape of an array.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

axis
Parameters:

axis (int)

class minerva.transforms.TransformPipeline(transforms)[source]

Bases: _Transform

Apply a sequence of transforms to a single sample of data and return the transformed data.

Apply a sequence of transforms to a single sample of data and return the transformed data.

Parameters

transformsList[_Transform]

A list of transforms to be applied to the input data.

__add__(other)[source]

Add a transform to the pipeline.

Parameters:

other (_Transform)

Return type:

TransformPipeline

__call__(x)[source]

Apply a sequence of transforms to a single sample of data and return the transformed data.

Parameters:

x (Any)

Return type:

Any

__radd__(other)[source]

Add a transform to the pipeline.

Parameters:

other (_Transform)

Return type:

TransformPipeline

__str__()[source]
Return type:

str

transforms
Parameters:

transforms (Sequence[_Transform])

class minerva.transforms.Transpose(axes)[source]

Bases: _Transform

Reorder the axes of numpy arrays.

Reorder the axes of numpy arrays.

Parameters

axesint

The order of the new axes

__call__(x)[source]

Reorder the axes of numpy arrays.

Parameters:

x (numpy.ndarray)

Return type:

numpy.ndarray

__str__()[source]
Return type:

str

axes
Parameters:

axes (Sequence[int])

class minerva.transforms.Unsqueeze(axis, label_only=False)[source]

Bases: _Transform

Add a new axis to the input data at the specified position.

Add a new axis to the input data at the specified position.

Parameters

axisint

The position of the new axis to be added.

label_onlybool, optional

If True, the transform will only apply to the label (second element) of the input tuple. If False, it will apply to the entire input data, by default False.

__call__(x)[source]

Add a new axis to the input data at the specified position.

Parameters:

x (numpy.ndarray)

__str__()[source]
Return type:

str

axis
label_only = False
Parameters:
  • axis (int)

  • label_only (bool)

class minerva.transforms._RandomSyncedTransform(num_samples=1, seed=None)[source]

Bases: minerva.transforms.transform._Transform

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

Orchestrate the application of a type of random transform to a list of data, ensuring that the same random state is used for all of them.

Parameters

transform_Transform

A transform that will be applied to the input data.

num_samplesint

The number of samples that will be transformed.

seedOptional[int], optional

The seed that will be used to generate the random state, by default None.

__call__(data)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

num_samples = 1
rng
abstract select_transform()[source]
transform
transformations_executed = 0
Parameters:
  • num_samples (int)

  • seed (Optional[int])

class minerva.transforms._Transform[source]

This class is a base class for all transforms. Transforms is just a fancy word for a function that takes an input and returns an output. The input and output can be anything. However, transforms operates over a single sample of data and does not require any additional information to perform the transformation. The __call__ method should be overridden in subclasses to define the transformation logic.

abstract __call__(*args, **kwargs)[source]

Implement the transformation logic in this method. Usually, the transformation is applied on a single sample of data.

Return type:

Any