minerva.transforms.random_transform¶
Classes¶
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. |
|
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. |
|
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. |
|
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. |
Module Contents¶
- class minerva.transforms.random_transform.RandomCrop(crop_size, num_samples=1, seed=None, pad_mode='reflect')[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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”.
- crop_size¶
- pad_mode = 'reflect'¶
- Parameters:
crop_size (Tuple[int, int])
num_samples (int)
seed (Optional[int])
pad_mode (str)
- class minerva.transforms.random_transform.RandomFlip(num_samples=1, possible_axis=1, prob=0.5, seed=None)[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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
- possible_axis = 1¶
- prob = 0.5¶
- Parameters:
num_samples (int)
possible_axis (Union[int, List[int]])
prob (float)
seed (Optional[int])
- class minerva.transforms.random_transform.RandomGrayScale(num_samples=1, seed=None, prob=0.1, method='luminosity')[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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.
- method = 'luminosity'¶
- prob = 0.1¶
- Parameters:
num_samples (int)
seed (Optional[int])
prob (float)
method (Literal['average', 'luminosity'])
- class minerva.transforms.random_transform.RandomResize(target_scale, ratio_range, num_samples, seed=None)[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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 resize transform that applies the same scale-based resize to multiple data items.
This transform randomly samples a scaling factor within a specified range and applies it to a base target scale to determine the final resize dimensions. The same scaling factor and resulting dimensions are applied to all related data items, ensuring consistency across image-mask pairs or other related data. This is useful for multi-scale training and data augmentation.
Parameters¶
- target_scaleTuple[int, int]
Base target dimensions as (height, width) in pixels that will be scaled by the random factor.
- ratio_rangeTuple[float, float]
Range of scaling factors as (min_ratio, max_ratio). The scaling factor is sampled uniformly from this range and applied to both dimensions.
- num_samplesint
The number of times the same random resize 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 scaling factor selection. If None, uses system randomness.
- ratio_range¶
- resize: minerva.transforms.transform._Transform | None = None¶
- target_scale¶
- Parameters:
target_scale (Tuple[int, int])
ratio_range (Tuple[float, float])
num_samples (int)
seed (Optional[int])
- class minerva.transforms.random_transform.RandomRotation(degrees, prob, num_samples=1, seed=None)[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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.
- degrees¶
- prob¶
- Parameters:
degrees (float)
prob (float)
num_samples (int)
seed (Optional[int])
- class minerva.transforms.random_transform.RandomSolarize(num_samples=1, seed=None, threshold=128, prob=1.0)[source]¶
Bases:
_RandomSyncedTransformOrchestrate 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.
- prob = 1.0¶
- threshold = 128¶
- Parameters:
num_samples (int)
seed (Optional[int])
threshold (int)
prob (float)
- class minerva.transforms.random_transform._RandomSyncedTransform(num_samples=1, seed=None)[source]¶
Bases:
minerva.transforms.transform._TransformOrchestrate 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¶
- transform¶
- transformations_executed = 0¶
- Parameters:
num_samples (int)
seed (Optional[int])