A hands-on exploration of contrastive learning on CIFAR-10
Abstract
This project implements SimCLR (Chen et al., 2020), a state-of-the-art self-supervised learning framework, to learn meaningful visual representations from unlabeled CIFAR-10 images. By leveraging contrastive learning and simple data augmentations, we achieve 82.4% linear evaluation accuracy – demonstrating the power of label-free representation learning for computer vision tasks.
- 1. Introduction to Self-Supervised Learning
The Label Efficiency Problem
Traditional supervised learning requires expensive labeled datasets. Self-supervised learning (SSL) circumvents this by creating supervisory signals directly from the data's structure.
Why SimCLR?
SimCLR's simplicity and effectiveness make it ideal for:
- Pretraining visual models with limited labels
- Studying fundamental representation learning
- Developing SSL research skills (highly relevant at UVic's computer vision labs) 2. Methodology Key Components
_**Component**_ **_Implementation Details_**
Base Encoder ResNet-50 (modified)
Projection Head 2-layer MLP (2048→512→128)
Augmentation Policy Random crop, flip, color jitter, blur
Contrastive Loss NT-Xent (τ=0.5)
Technical Workflow
Input Pipeline:
Generate two augmented views per image
transform = Compose([
RandomResizedCrop(32),
RandomHorizontalFlip(),
ColorJitter(0.8, 0.8, 0.8, 0.2)
])
Training:
Maximize similarity between positive pairs
Minimize similarity across negatives
Evaluation:
Linear probing on frozen features
3. Results & Analysis
Performance Metrics
Epochs Batch Size Top-1 Accuracy
100 256 82.4%
4. Practical Applications
This implementation demonstrates how SSL can benefit:
- Medical Imaging: Learn from unlabeled scans
- Remote Sensing: Pretrain on satellite imagery
- Robotics: Develop visual priors with minimal supervision
5. Getting Started
Implementation Guide :
# Clone repository
git clone https://github.com/zahramh99/simclr-cifar10.git
cd simclr-cifar10
# Install dependencies
pip install -r requirements.txt
# Train model
python train.py
Custom Dataset Adaptation
- Replace images in ./data/custom/
- Modify config.py:
dataset = "custom"
image_size = 32 # Match CIFAR-10 dimensions
6. Conclusion
This project verifies that SimCLR can learn high-quality representations without labels, achieving competitive performance on CIFAR-10. The modular PyTorch implementation serves as:
- A practical SSL tutorial
- A baseline for future research
- A template for industrial applications
Future Work: Extend to DINOv2 or investigate hybrid supervised/self-supervised approaches.
References
- Chen et al. (2020). A Simple Framework for Contrastive Learning. arXiv:2002.05709
Author: Zahra Gharehmahmoodlee
GitHub: github.com/zahramh99/simclr-cifar10
Top comments (0)