Skip to content
AI360Xpert
Beta

Rotation Prediction

Rotation prediction spins each photo by a random right angle and asks the network which way, forcing it to learn what upright objects look like.

Predicting which right angle spun each photo forces networks to learn upright object structure
Predicting which right angle spun each photo forces networks to learn upright object structure

Why Does This Exist?

Orientation understanding hides inside every recognition task: dogs have legs below heads, skies sit above ground, text reads left to right. Supervised labels teach these facts incidentally and expensively. A free exercise targeting orientation directly would front-load the most universal visual knowledge.

Rotation prediction is that exercise. Spin each image by a multiple of 9090 degrees, ask the network for the angle, and backpropagate. Upright-ness must be learned to score above chance, and upright-ness transfers everywhere. The exercise family is pretext tasks, inside the framework of self-supervised learning.

Think of It Like This

A gallery guard spotting hung paintings

A gallery guard learns every painting so well they notice instantly when one hangs sideways overnight. They never studied art history; thousands of walk-throughs built an expectation of upright for every frame, and violations pop out.

The network is the guard and rotations are the nightly pranks. Expectation of upright is the transferable knowledge. It fails on symmetric art: circular canvases hang any way without offence, and no guard catches those, which is the symmetry limit below.

How It Actually Works

For image xx, sample k∈{0,1,2,3}k \in \{0, 1, 2, 3\} uniformly and rotate by k×90k \times 90 degrees. The network outputs four logits; loss is cross-entropy against kk:

L=−log⁡ezk∑jezj,k∼Uniform(0,3)L = -\log \frac{e^{z_k}}{\sum_j e^{z_j}}, \qquad k \sim \mathrm{Uniform}(0, 3)

Only multiples of 9090 degrees avoid interpolation artefacts that would leak the answer through blur patterns. After pretraining, the classification head is discarded and convolutional features transfer to detection and segmentation with far less labelled data.

Worked example

Logits [1.2,2.5,0.3,−0.5][1.2, 2.5, 0.3, -0.5] for true k=1k = 1. Exponentials 3.32,12.18,1.35,0.613.32, 12.18, 1.35, 0.61 sum to 17.4617.46; probabilities [0.19,0.70,0.08,0.03][0.19, 0.70, 0.08, 0.03]. Loss is −log⁡(0.70)=0.36-\log(0.70) = 0.36. The network is 7070 percent sure of 9090 degrees from cues like sky position and text baseline, exactly the upright knowledge downstream tasks reuse.

Code

Rotation loss on one spun photo, the complete exercise step.

import numpy as np

def rotation_loss(logits: np.ndarray, k: int) -> float:    """Cross-entropy against the known spin index."""    e = np.exp(logits - logits.max())  # shift for numerical safety    return round(float(-np.log(e[k] / e.sum())), 2)

print(rotation_loss(np.array([1.2, 2.5, 0.3, -0.5]), 1))  # -> 0.36 confidentprint(rotation_loss(np.array([0.1, 0.1, 0.1, 0.1]), 2))  # -> 1.39 pure chance

Watch Out For

Symmetric images with no correct answer

Balls, top-down textures, and centred flowers look identical under rotation. The exercise punishes correct networks for unanswerable questions, injecting pure noise into gradients.

Filter near-symmetric images from pretraining or accept the noise floor. Chance-level subsets do not indicate broken training, only unanswerable homework.

Interpolation artefacts from non-right angles

Rotate by 3737 degrees and resampling blur patterns correlate with the angle, handing the network a cheat code written in pixels. Scores soar while features learn resampling, not objects.

Stick to exact multiples of 9090 degrees with nearest-exact transforms. Audit with artefact-free validation before celebrating accuracy.

The Quick Version

  • Rotation prediction classifies spins of 00, 9090, 180180, 270270 degrees with free labels.
  • Our logits give 7070 percent confidence on the true spin for loss 0.360.36.
  • Chance-level guessing scores 1.391.39, the floor every run must beat.
  • Upright-ness learned this way transfers to detection and segmentation.
  • Symmetric images and interpolated angles are the two homework traps.