Table of Contents

Class OneOf<T, TData>

Namespace
AiDotNet.Augmentation
Assembly
AiDotNet.dll

Randomly selects and applies exactly one augmentation from a set.

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

Type Parameters

T

The numeric type for calculations.

TData

The data type being augmented.

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

Remarks

OneOf randomly chooses one augmentation from the provided set and applies it. This is useful when you want variety but don't want to apply multiple similar augmentations that might compound their effects too strongly.

For Beginners: Think of this like flipping a coin to decide which transformation to apply. You might flip the image OR rotate it, but not both at the same time.

Example usage:

var randomTransform = new OneOf<float, ImageTensor<float>>(
    new HorizontalFlip<float>(),
    new VerticalFlip<float>(),
    new Rotation<float>()
);
var augmented = randomTransform.Apply(image, context);

Constructors

OneOf(params IAugmentation<T, TData>[])

Creates a new OneOf with uniform weights.

public OneOf(params IAugmentation<T, TData>[] augmentations)

Parameters

augmentations IAugmentation<T, TData>[]

The augmentations to choose from.

OneOf(IEnumerable<IAugmentation<T, TData>>, double)

Creates a new OneOf with uniform weights.

public OneOf(IEnumerable<IAugmentation<T, TData>> augmentations, double probability = 1)

Parameters

augmentations IEnumerable<IAugmentation<T, TData>>

The augmentations to choose from.

probability double

The probability of applying any augmentation (default 1.0).

OneOf(IEnumerable<(IAugmentation<T, TData> augmentation, double weight)>, double)

Creates a new OneOf with specified weights.

public OneOf(IEnumerable<(IAugmentation<T, TData> augmentation, double weight)> augmentationsWithWeights, double probability = 1)

Parameters

augmentationsWithWeights IEnumerable<(IAugmentation<T, TData> augmentation, double weight)>

The augmentations with their selection weights.

probability double

The probability of applying any augmentation (default 1.0).

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.

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

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.