This repository provides a modular and reproducible implementation of ResNet and PlainNet as described in He et al. (2015). It is designed to support ImageNet-scale training using modern PyTorch infrastructure: Lightning, Hydra, WebDataset, and W&B.
- From-scratch ResNet and PlainNet implementations (BasicBlock and Bottleneck)
- Trains ResNet-50 on ImageNet using WebDataset format
- Modular configuration using Hydra
- Scalable training with PyTorch Lightning (DDP, AMP, checkpointing)
- Integrated with Weights & Biases for logging and tracking
- Export script to extract raw
state_dictweights from Lightning checkpoint - Pre-commit integration: Black, Flake8, isort, nbQA
ImageNet training was performed on the following GCP instance:
- Instance Type:
a2-highgpu-2g - GPUs: 2 × NVIDIA A100 (40GB each)
- CPU: 24 vCPUs (12 physical cores with hyperthreading)
- RAM: 170 GB system memory
This configuration is sufficient for full-batch ImageNet training using WebDataset and mixed precision.
Runs are configured via Hydra. For example:
# configs/experiment/train_imagenet.yaml
# @package _global_
experiment:
name: train_imagenet
tags: ["resnet", "imagenet", "resnet50"]python train.py experiment=train_imagenetHydra composes the full configuration (model, dataset, optimizer, scheduler, logger, trainer) automatically.
Convert a Lightning checkpoint into raw state_dict weights for deployment or fine-tuning:
python export.py \
--ckpt-path path/to/checkpoint.ckpt \
--output-path resnet50-imagenet.pt \
experiment=train_imagenetThe script reconstructs the model using Hydra config and saves the weights via torch.save.
This project uses ImageNet from:
To download and organize the WebDataset shards:
python src/utils/setup_imagenet_wds.pyThis creates the following directory structure:
datasets/wds_imagenet1k/
├── train/
│ ├── imagenet1k-train-0000.tar
│ └── ...
└── validation/
├── imagenet1k-validation-00.tar
└── ...
Matches configs/dataset/imagenet_wds.yaml.
configs/ # Hydra configs (datasets, models, training, logger, etc.)
src/models/ # ResNet and PlainNet implementations (blocks, stems)
src/data/ # LightningDataModules for CIFAR and ImageNet
src/utils/ # WebDataset utilities, export script, synthetic data
train.py # Entry point for Hydra-based training
export.py # Converts Lightning checkpoint to raw model weights
Main dependencies:
torch,torchvisionlightning>=2.0(PyTorch Lightning)hydra-core,omegaconfwandb,optuna,webdatasetpre-commit,black,flake8,isort,nbQA
Install all requirements:
pip install -r requirements.txt