$ cd ../
SimCLR — Self-Supervised contrastive learning — bash

user@devops:~$ cat README.md

SimCLR — Self-Supervised contrastive learning

# Description

SimCLR (Chen, Kornblith, Norouzi & Hinton, 2020) implemented from scratch in PyTorch on Fashion-MNIST (3,000 training images, 1,000 test, seed 42, CPU). Core idea of contrastive self-supervised learning: a network learns useful visual representations WITHOUT any label, only by maximizing similarity between two augmented views of the same image (positive pair) and minimizing it against the rest of the batch (negatives). Architecture: CNN encoder with 109,632 params (Conv 1→32→64→128ch with BatchNorm + MaxPool + AdaptiveAvgPool + FC 128) and MLP projection head with 24,768 params (FC 128→128 ReLU → FC 128→64, L2-normalized output on the unit sphere). SimCLR augmentations: RandomResizedCrop (scale 0.55–1.0), horizontal flip and color jitter — random crop is the paper's key recipe. NT-Xent (InfoNCE) loss with temperature τ=0.5 and batch 256 (512 views, 1 positive + 510 negatives per image): Adam lr 3e-3 with cosine annealing, 25 epochs, ~3 min CPU, loss 5.36→4.59. Evaluation with the paper's standard protocol (linear eval: logistic regression on frozen embeddings): random init 41.3% vs SimCLR 76.8% (+35.5 pp) vs supervised end-to-end 76.5% — SimCLR matches supervised with zero labels at −0.3 pp. Representation quality grows during training (probe every 3 epochs: 71.9%→76.8%). kNN on embeddings without training a classifier: SimCLR > random at every k (k=10: 73.9% vs 67.1%). t-SNE: SimCLR groups by class (Trouser, Sneaker, Bag form clusters), random init stays scattered. Cosine similarity matrix: the diagonal (positive pairs) dominates. Deterministic checkpoint to skip retraining. 7 visualizations.

# Key features

$ Self-Supervised Learning with SimCLR (Chen et al. 2020) from scratch in PyTorch: 0 labels used during training, only augmented view pairs

$ NT-Xent (InfoNCE) loss with temperature τ=0.5: 1 positive + 510 negatives per image in batch 256 (512 views)

$ CNN encoder with 109,632 params (Conv 32→64→128ch, BN, MaxPool, AdaptiveAvgPool) + MLP projection head 24,768 params with L2-normalized output

$ SimCLR augmentations: RandomResizedCrop (scale 0.55–1.0), horizontal flip and color jitter — two independent views per image

$ Linear eval (standard protocol): SimCLR 76.8% matches supervised end-to-end 76.5% and beats random init 41.3% by +35.5 pp

$ Representations improve with training: linear probe every 3 epochs from 71.9% to 76.8%

$ kNN on embeddings without training: SimCLR beats random at every k (k=10: 73.9% vs 67.1%)

$ 7 visualizations: augmentation pairs, NT-Xent loss, linear eval progress, baseline comparison, t-SNE, kNN sweep and similarity matrix

# Gallery

Terminal del proyecto
SimCLR — Self-Supervised contrastive learning - Terminal del proyecto
Pares de aumentaciones SimCLR
SimCLR — Self-Supervised contrastive learning - Pares de aumentaciones SimCLR
Loss NT-Xent (contrastiva)
SimCLR — Self-Supervised contrastive learning - Loss NT-Xent (contrastiva)
Eval lineal por época
SimCLR — Self-Supervised contrastive learning - Eval lineal por época
Random vs SimCLR vs Supervisado
SimCLR — Self-Supervised contrastive learning - Random vs SimCLR vs Supervisado
t-SNE: SimCLR agrupa, random no
SimCLR — Self-Supervised contrastive learning - t-SNE: SimCLR agrupa, random no
Barrido kNN sobre embeddings
SimCLR — Self-Supervised contrastive learning - Barrido kNN sobre embeddings
Similitud coseno vista A vs B
SimCLR — Self-Supervised contrastive learning - Similitud coseno vista A vs B

# Technologies used

Python PyTorch NumPy Matplotlib