Table of Contents

Class Compose<T, TData>

Namespace
AiDotNet.Augmentation
Assembly
AiDotNet.dll

Applies multiple augmentations sequentially.

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

Type Parameters

T

The numeric type for calculations.

TData

The data type being augmented.

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

Remarks

Compose chains multiple augmentations together, applying them one after another. Each augmentation sees the output of the previous one. This is the most common way to build augmentation pipelines.

For Beginners: Think of this like a recipe with multiple steps. First flip the image, then adjust brightness, then add noise. Each step transforms the result of the previous step.

Example usage:

var pipeline = new Compose<float, ImageTensor<float>>(
    new HorizontalFlip<float>(),
    new Brightness<float>(),
    new GaussianNoise<float>()
);
var augmented = pipeline.Apply(image, context);

Constructors

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

Creates a new composition of augmentations.

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

Parameters

augmentations IAugmentation<T, TData>[]

The augmentations to apply in sequence.

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

Creates a new composition of augmentations.

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

Parameters

augmentations IEnumerable<IAugmentation<T, TData>>

The augmentations to apply in sequence.

probability double

The probability of applying this entire pipeline (default 1.0).

Properties

Augmentations

Gets the list of augmentations in this composition.

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.

With(IAugmentation<T, TData>)

Creates a new composition with an additional augmentation appended.

public Compose<T, TData> With(IAugmentation<T, TData> augmentation)

Parameters

augmentation IAugmentation<T, TData>

The augmentation to append.

Returns

Compose<T, TData>

A new Compose instance with the augmentation added.

Remarks

This method returns a new immutable instance rather than modifying the current one, making it safe for use in multi-threaded scenarios.