Table of Contents

Class SomeOf<T, TData>

Namespace
AiDotNet.Augmentation
Assembly
AiDotNet.dll

Randomly selects and applies N augmentations from a set.

public class SomeOf<T, TData> : ISpatialAugmentation<T, TData>, IAugmentation<T, TData>

Type Parameters

T

The numeric type for calculations.

TData

The data type being augmented.

Inheritance
SomeOf<T, TData>
Implements
IAugmentation<T, TData>
Inherited Members

Remarks

SomeOf randomly chooses N augmentations from the provided set and applies them in sequence. The number N can be fixed or randomly sampled from a range. This provides more variety than OneOf while still limiting the total augmentation.

For Beginners: Think of this like drawing cards from a deck. You pick 2 or 3 random transformations and apply them one after another. This creates more variety in your training data.

Example usage:

var randomTransforms = new SomeOf<float, ImageTensor<float>>(
    n: 2,
    new HorizontalFlip<float>(),
    new VerticalFlip<float>(),
    new Rotation<float>(),
    new Scale<float>()
);
var augmented = randomTransforms.Apply(image, context);

Constructors

SomeOf(int, params IAugmentation<T, TData>[])

Creates a new SomeOf with a fixed number of augmentations.

public SomeOf(int n, params IAugmentation<T, TData>[] augmentations)

Parameters

n int

The number of augmentations to apply.

augmentations IAugmentation<T, TData>[]

The augmentations to choose from.

SomeOf(int, IEnumerable<IAugmentation<T, TData>>, double, bool)

Creates a new SomeOf with a fixed number of augmentations.

public SomeOf(int n, IEnumerable<IAugmentation<T, TData>> augmentations, double probability = 1, bool randomizeOrder = true)

Parameters

n int

The number of augmentations to apply.

augmentations IEnumerable<IAugmentation<T, TData>>

The augmentations to choose from.

probability double

The probability of applying any augmentation (default 1.0).

randomizeOrder bool

Whether to randomize the order of application (default true).

SomeOf(int, int, IEnumerable<IAugmentation<T, TData>>, double, bool)

Creates a new SomeOf with a range of augmentations to apply.

public SomeOf(int minN, int maxN, IEnumerable<IAugmentation<T, TData>> augmentations, double probability = 1, bool randomizeOrder = true)

Parameters

minN int

The minimum number of augmentations to apply.

maxN int

The maximum number of augmentations to apply.

augmentations IEnumerable<IAugmentation<T, TData>>

The augmentations to choose from.

probability double

The probability of applying any augmentation (default 1.0).

randomizeOrder bool

Whether to randomize the order of application (default true).

Properties

Augmentations

Gets the list of augmentations to choose from.

public IReadOnlyList<IAugmentation<T, TData>> Augmentations { get; }

Property Value

IReadOnlyList<IAugmentation<T, TData>>

IsEnabled

Gets whether this augmentation is currently enabled.

public bool IsEnabled { get; set; }

Property Value

bool

IsTrainingOnly

Gets whether this augmentation should only be applied during training.

public bool IsTrainingOnly { get; set; }

Property Value

bool

Remarks

Most augmentations are training-only. Test-Time Augmentation (TTA) uses specific augmentations during inference to improve predictions.

MaxN

Gets the maximum number of augmentations to apply.

public int MaxN { get; }

Property Value

int

MinN

Gets the minimum number of augmentations to apply.

public int MinN { get; }

Property Value

int

Name

Gets the name of this augmentation for logging and debugging.

public string Name { get; }

Property Value

string

Probability

Gets the probability of this augmentation being applied (0.0 to 1.0).

public double Probability { get; }

Property Value

double

RandomizeOrder

Gets whether the selected augmentations should be applied in random order.

public bool RandomizeOrder { get; }

Property Value

bool

SupportsBoundingBoxes

Gets whether this augmentation supports bounding box transformation.

public bool SupportsBoundingBoxes { get; }

Property Value

bool

SupportsKeypoints

Gets whether this augmentation supports keypoint transformation.

public bool SupportsKeypoints { get; }

Property Value

bool

SupportsMasks

Gets whether this augmentation supports segmentation mask transformation.

public bool SupportsMasks { get; }

Property Value

bool

Methods

Apply(TData, AugmentationContext<T>?)

Applies the augmentation to the input data.

public TData Apply(TData data, AugmentationContext<T>? context = null)

Parameters

data TData

The input data to augment.

context AugmentationContext<T>

The augmentation context containing random state and targets.

Returns

TData

The augmented data.

ApplyWithTargets(AugmentedSample<T, TData>, AugmentationContext<T>?)

Applies the augmentation and transforms all spatial targets.

public AugmentedSample<T, TData> ApplyWithTargets(AugmentedSample<T, TData> sample, AugmentationContext<T>? context = null)

Parameters

sample AugmentedSample<T, TData>

The augmented sample containing data and targets.

context AugmentationContext<T>

The augmentation context.

Returns

AugmentedSample<T, TData>

The augmented sample with transformed targets.

GetParameters()

Gets the parameters of this augmentation for serialization/logging.

public IDictionary<string, object> GetParameters()

Returns

IDictionary<string, object>

A dictionary of parameter names to values.