Class SSLAugmentationPolicies<T>
- Namespace
- AiDotNet.SelfSupervisedLearning
- Assembly
- AiDotNet.dll
Provides standard augmentation policies for self-supervised learning methods.
public class SSLAugmentationPolicies<T>
Type Parameters
TThe numeric type used for computations (typically float or double).
- Inheritance
-
SSLAugmentationPolicies<T>
- Inherited Members
Remarks
For Beginners: Self-supervised learning methods rely heavily on data augmentation to create different "views" of the same image. These views should be different enough to be challenging, but similar enough that they can still be recognized as the same image.
Common augmentations for SSL:
- Random crop and resize: Most important - crops different regions
- Color jitter: Changes brightness, contrast, saturation, hue
- Grayscale: Removes color information
- Gaussian blur: Adds blur (important for SimCLR, BYOL)
- Horizontal flip: Random left-right flip
- Solarization: Inverts pixels above threshold (BYOL, DINO)
Method-specific policies:
- SimCLR: Strong augmentation with blur and color jitter
- MoCo v2: Similar to SimCLR with slightly different parameters
- BYOL: Asymmetric augmentation (view 1 and view 2 different)
- DINO: Multi-crop strategy (global + local crops)
Constructors
SSLAugmentationPolicies(int?)
Initializes a new instance of the SSLAugmentationPolicies class.
public SSLAugmentationPolicies(int? seed = null)
Parameters
seedint?Optional random seed for reproducibility.
Methods
ApplyBYOL(Tensor<T>)
Applies BYOL-style asymmetric augmentation.
public (Tensor<T> view1, Tensor<T> view2) ApplyBYOL(Tensor<T> image)
Parameters
imageTensor<T>Input image tensor.
Returns
Remarks
BYOL uses asymmetric augmentation:
View 1: Full augmentation pipeline
View 2: Lighter augmentation (may skip some transforms)
ApplyDINO(Tensor<T>, int, int)
Applies DINO-style multi-crop augmentation.
public (Tensor<T>[] globalViews, Tensor<T>[] localViews) ApplyDINO(Tensor<T> image, int numGlobalCrops = 2, int numLocalCrops = 8)
Parameters
imageTensor<T>Input image tensor.
numGlobalCropsintNumber of global (large) crops (default: 2).
numLocalCropsintNumber of local (small) crops (default: 8).
Returns
- (Tensor<T>[] globalViews, Tensor<T>[] localViews)
Global and local crop views.
Remarks
DINO multi-crop strategy:
- Global crops: 224x224, covering 50-100% of image
- Local crops: 96x96, covering 5-50% of image
- Teacher sees only global crops, student sees all crops
ApplyMinimal(Tensor<T>)
Applies minimal augmentation (used by MAE which relies on masking rather than augmentation).
public Tensor<T> ApplyMinimal(Tensor<T> image)
Parameters
imageTensor<T>Input image tensor.
Returns
- Tensor<T>
Minimally augmented image.
Remarks
For Beginners: MAE uses minimal augmentation because the masking itself provides the learning signal. Only basic normalization and optional horizontal flip.
ApplyMoCoV2(Tensor<T>)
Applies MoCo v2 style augmentation.
public (Tensor<T> query, Tensor<T> key) ApplyMoCoV2(Tensor<T> image)
Parameters
imageTensor<T>Input image tensor.
Returns
ApplySimCLR(Tensor<T>)
Applies SimCLR-style augmentation to create two views.
public (Tensor<T> view1, Tensor<T> view2) ApplySimCLR(Tensor<T> image)
Parameters
imageTensor<T>Input image tensor [C, H, W] or [B, C, H, W].
Returns
Remarks
SimCLR augmentation pipeline:
RandomResizedCrop(224, scale=(0.08, 1.0))
RandomHorizontalFlip(p=0.5)
ColorJitter(brightness=0.8, contrast=0.8, saturation=0.8, hue=0.2, p=0.8)
RandomGrayscale(p=0.2)
GaussianBlur(kernel_size=23, sigma=(0.1, 2.0), p=0.5)
ForBYOL(int?)
Creates a standard BYOL augmentation policy.
public static SSLAugmentationPolicies<T> ForBYOL(int? seed = null)
Parameters
seedint?
Returns
ForDINO(int?)
Creates a standard DINO augmentation policy.
public static SSLAugmentationPolicies<T> ForDINO(int? seed = null)
Parameters
seedint?
Returns
ForSimCLR(int?)
Creates a standard SimCLR augmentation policy.
public static SSLAugmentationPolicies<T> ForSimCLR(int? seed = null)
Parameters
seedint?