MAEReconstructionLoss<T>

Models & Types · AiDotNet.SelfSupervisedLearning.Losses

MAE (Masked Autoencoder) Reconstruction Loss for self-supervised learning.

Inheritance: ContrastiveLossBase<T> → MAEReconstructionLoss<T>

For Beginners

MAE loss measures how well the model reconstructs masked patches of an image. Only the masked patches contribute to the loss, making it efficient and focused on learning useful representations.

How It Works

Key insight: By masking a large portion (75%) of patches and reconstructing only those patches, the model learns rich visual representations without requiring contrastive learning or negative samples.

Loss formula:

where M is the number of masked patches.

Reference: He et al., “Masked Autoencoders Are Scalable Vision Learners” (CVPR 2022)

Constructors

Constructor Summary
MAEReconstructionLoss(bool normalize, bool perPatchNormalization) Initializes a new instance of the MAEReconstructionLoss class.

Methods

Method Summary
T ComputeLoss(Tensor<T> reconstructed, Tensor<T> original, Tensor<T> mask) Computes the reconstruction loss for masked patches.
T[] ComputePerSampleLoss(Tensor<T> reconstructed, Tensor<T> original, Tensor<T> mask) Computes per-sample reconstruction loss (useful for analysis).
Tensor<T> ComputeLoss(Tensor<T> view1, Tensor<T> view2) The differentiable MAE reconstruction objective, built entirely from IEngine operations, over all positions.
Tensor<T> CreateRandomMask(int batchSize, int numPatches, double maskRatio, int? seed) Creates a random mask for patches.
ValueTuple<T, Tensor<T>> ComputeLossWithGradients(Tensor<T> reconstructed, Tensor<T> original, Tensor<T> mask) Computes reconstruction loss with gradients for backpropagation.