RotationPredictionLoss<T>
Models & Types · AiDotNet.LossFunctions
Self-supervised loss function based on rotation prediction for images.
Inheritance: LossFunctionBase<T> → RotationPredictionLoss<T>
Implements: ISelfSupervisedLoss<T>
For Beginners
This teaches the model to understand image structure without labels.
Imagine showing someone 100 photos, each rotated randomly:
- They learn to recognize: which way is “up”, spatial relationships, object orientations
- They don’t need to know: what the objects are (no labels needed)
After this training, when you show them 5 labeled cat photos:
- They already understand image structure
- They just need to learn: “cats look like THIS”
- Much faster than learning everything from scratch!
How it works:
- Take each unlabeled image
- Create 4 versions: rotated by 0°, 90°, 180°, 270°
- Label each version: 0, 1, 2, 3 (which rotation was applied)
- Train model to predict the rotation
What the model learns:
- Edge orientations
- Spatial relationships
- Object structure
- “Natural” vs “unnatural” orientations
These features are very useful for actual classification tasks!
How It Works
Rotation prediction is a self-supervised task where:
- Images are rotated by 0°, 90°, 180°, or 270°
- Model predicts which rotation was applied (4-class classification)
- Model learns spatial relationships and features without needing class labels
Example
using AiDotNet.LossFunctions;
using AiDotNet.Tensors.LinearAlgebra;
var loss = new RotationPredictionLoss<float>();
var predicted = new Vector<float>(new[] { 0.9f, 0.2f, 0.7f });
var actual = new Vector<float>(new[] { 1.0f, 0.0f, 1.0f });
float value = loss.CalculateLoss(predicted, actual);
Console.WriteLine($"RotationPredictionLoss = {value:F4}");
Constructors
| Constructor | Summary |
|---|---|
RotationPredictionLoss() |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> target) |
Categorical cross-entropy loss for rotation prediction (4-class). |
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |
|
ValueTuple<TInput, TOutput> CreateTask(TInput input) |