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
TThe numeric type for calculations.
TDataThe data type being augmented.
- Inheritance
-
SomeOf<T, TData>
- Implements
-
ISpatialAugmentation<T, TData>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
nintThe number of augmentations to apply.
augmentationsIAugmentation<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
nintThe number of augmentations to apply.
augmentationsIEnumerable<IAugmentation<T, TData>>The augmentations to choose from.
probabilitydoubleThe probability of applying any augmentation (default 1.0).
randomizeOrderboolWhether 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
minNintThe minimum number of augmentations to apply.
maxNintThe maximum number of augmentations to apply.
augmentationsIEnumerable<IAugmentation<T, TData>>The augmentations to choose from.
probabilitydoubleThe probability of applying any augmentation (default 1.0).
randomizeOrderboolWhether 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
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.
MaxN
Gets the maximum number of augmentations to apply.
public int MaxN { get; }
Property Value
MinN
Gets the minimum number of augmentations to apply.
public int MinN { get; }
Property Value
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
RandomizeOrder
Gets whether the selected augmentations should be applied in random order.
public bool RandomizeOrder { 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.