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
TThe numeric type for calculations.
TDataThe data type being augmented.
- Inheritance
-
OneOf<T, TData>
- Implements
-
ISpatialAugmentation<T, TData>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
augmentationsIAugmentation<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
augmentationsIEnumerable<IAugmentation<T, TData>>The augmentations to choose from.
probabilitydoubleThe 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
augmentationsWithWeightsIEnumerable<(IAugmentation<T, TData> augmentation, double weight)>The augmentations with their selection weights.
probabilitydoubleThe 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
IsTrainingOnly
Gets whether this augmentation should only be applied during training.
public bool IsTrainingOnly { get; set; }
Property Value
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
Probability
Gets the probability of this augmentation being applied (0.0 to 1.0).
public double Probability { get; }
Property Value
SupportsBoundingBoxes
Gets whether this augmentation supports bounding box transformation.
public bool SupportsBoundingBoxes { get; }
Property Value
SupportsKeypoints
Gets whether this augmentation supports keypoint transformation.
public bool SupportsKeypoints { get; }
Property Value
SupportsMasks
Gets whether this augmentation supports segmentation mask transformation.
public bool SupportsMasks { get; }
Property Value
Methods
Apply(TData, AugmentationContext<T>?)
Applies the augmentation to the input data.
public TData Apply(TData data, AugmentationContext<T>? context = null)
Parameters
dataTDataThe input data to augment.
contextAugmentationContext<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
sampleAugmentedSample<T, TData>The augmented sample containing data and targets.
contextAugmentationContext<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.