Table of Contents

Class RotationPredictionLoss<T>

Namespace
AiDotNet.LossFunctions
Assembly
AiDotNet.dll

Self-supervised loss function based on rotation prediction for images.

public class RotationPredictionLoss<T> : ISelfSupervisedLoss<T>

Type Parameters

T

The numeric data type (e.g., float, double).

Inheritance
RotationPredictionLoss<T>
Implements
Inherited Members

Remarks

Rotation prediction is a self-supervised task where: 1. Images are rotated by 0°, 90°, 180°, or 270° 2. Model predicts which rotation was applied (4-class classification) 3. Model learns spatial relationships and features without needing class labels

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:

  1. Take each unlabeled image
  2. Create 4 versions: rotated by 0°, 90°, 180°, 270°
  3. Label each version: 0, 1, 2, 3 (which rotation was applied)
  4. 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!

Methods

CreateTask<TInput, TOutput>(TInput)

Creates a self-supervised task from unlabeled input data.

public (TInput augmentedX, TOutput augmentedY) CreateTask<TInput, TOutput>(TInput input)

Parameters

input TInput

Unlabeled input data (e.g., images).

Returns

(TInput Input, TOutput Output)

A tuple containing:

  • augmentedX: Transformed input data for the self-supervised task
  • augmentedY: Labels for the self-supervised task (e.g., rotation angles)

Type Parameters

TInput
TOutput

Remarks

This method transforms unlabeled data into a supervised learning problem by creating artificial labels based on the transformation applied.

For Beginners: This converts "unlabeled data" into a "labeled learning problem".

Example for rotation prediction:

  • Input: 10 unlabeled images
  • Output: 40 labeled images (each original rotated 4 times: 0°, 90°, 180°, 270°)
  • Labels: [0, 1, 2, 3] indicating which rotation was applied

The model learns to recognize rotations, which teaches it about:

  • Edge orientations
  • Spatial relationships
  • Object structure

These learned features are useful for the actual classification task!