Class MoCoV2<T>
- Namespace
- AiDotNet.SelfSupervisedLearning
- Assembly
- AiDotNet.dll
MoCo v2: Improved Baselines with Momentum Contrastive Learning.
public class MoCoV2<T> : MoCo<T>, ISSLMethod<T>
Type Parameters
TThe numeric type used for computations.
- Inheritance
-
MoCo<T>MoCoV2<T>
- Implements
-
ISSLMethod<T>
- Inherited Members
Remarks
For Beginners: MoCo v2 improves on MoCo v1 by incorporating ideas from SimCLR: an MLP projection head and stronger augmentations. This combines MoCo's memory efficiency with SimCLR's representation quality improvements.
Key improvements over MoCo v1:
- MLP projection head: 2-layer MLP instead of linear (from SimCLR)
- Stronger augmentations: Added blur and more color distortion (from SimCLR)
- Cosine learning rate schedule: Better training dynamics
Result: MoCo v2 matches SimCLR performance with much smaller batch sizes (256 vs 4096-8192).
Reference: Chen et al., "Improved Baselines with Momentum Contrastive Learning" (arXiv 2020)
Constructors
MoCoV2(INeuralNetwork<T>, IMomentumEncoder<T>, IProjectorHead<T>, IProjectorHead<T>, int, SSLConfig?)
Initializes a new instance of the MoCoV2 class.
public MoCoV2(INeuralNetwork<T> encoder, IMomentumEncoder<T> momentumEncoder, IProjectorHead<T> projector, IProjectorHead<T> momentumProjector, int embeddingDim = 128, SSLConfig? config = null)
Parameters
encoderINeuralNetwork<T>The online encoder network.
momentumEncoderIMomentumEncoder<T>The momentum encoder.
projectorIProjectorHead<T>The MLP projection head for online encoder.
momentumProjectorIProjectorHead<T>The MLP projection head for momentum encoder.
embeddingDimintDimension of the output embeddings.
configSSLConfigOptional SSL configuration.
Properties
Name
Gets the name of this SSL method.
public override string Name { get; }
Property Value
Remarks
Examples: "SimCLR", "MoCo v2", "BYOL", "DINO", "MAE"
Methods
Create(INeuralNetwork<T>, Func<INeuralNetwork<T>, INeuralNetwork<T>>, int, int, int, int)
Creates a MoCo v2 instance with default configuration.
public static MoCoV2<T> Create(INeuralNetwork<T> encoder, Func<INeuralNetwork<T>, INeuralNetwork<T>> createEncoderCopy, int encoderOutputDim, int projectionDim = 128, int hiddenDim = 2048, int queueSize = 65536)
Parameters
encoderINeuralNetwork<T>The backbone encoder.
createEncoderCopyFunc<INeuralNetwork<T>, INeuralNetwork<T>>Function to create a copy of the encoder for momentum.
encoderOutputDimintOutput dimension of the encoder.
projectionDimintDimension of the projection space (default: 128).
hiddenDimintHidden dimension of the projector MLP (default: 2048).
queueSizeintSize of the memory queue (default: 65536).
Returns
- MoCoV2<T>
A configured MoCo v2 instance.