An open API service indexing awesome lists of open source software.

https://github.com/reneking-tech/cifar10-lightning

Hands-on deep learning with PyTorch & Lightning β€” CIFAR-10 classification
https://github.com/reneking-tech/cifar10-lightning

ai cifar10 cnn deep-learning image-classification machine-learning ml-engineering model-evaluation notebooks python pytorch pytorch-lightning transfer-learning

Last synced: about 2 months ago
JSON representation

Hands-on deep learning with PyTorch & Lightning β€” CIFAR-10 classification

Awesome Lists containing this project

README

          

# 🧠 CIFAR-10 Classifier: From PyTorch to Lightning

This project demonstrates how to build and train a simple Convolutional Neural Network (CNN) on the CIFAR-10 image classification dataset using both **vanilla PyTorch** and **PyTorch Lightning**.

It was created as a practical, hands-on learning journey after completing Andrew Ng's Machine Learning Specialization. The goal: go from foundational ML understanding to real model implementation and training.

---

## πŸš€ What’s Inside

- βœ… CIFAR-10 data loading with torchvision
- 🧱 CNN architecture (`SimpleCNN`)
- πŸ” Custom training + validation loops
- ⚑ PyTorch Lightning module (`LitCNN`)
- πŸ“ˆ Loss/accuracy visualization
- πŸ’‘ Reflections on overfitting + improvements
- βœ… Pre-commit auto-formatting, notebook cleaning, code linting

---

## πŸ“Š Training Results

### Vanilla PyTorch (5 Epochs)

- Final **Train Acc:** ~98%
- Final **Val Acc:** ~71%
- ❗ Validation loss increased β†’ signs of **overfitting**

### PyTorch Lightning (5 Epochs)

- Final **Val Loss:** ~0.83
- Final **Val Accuracy:** ~71.2%

> πŸ” Same accuracy, but Lightning yielded a cleaner validation curve and easier setup.

---

## πŸ–ΌοΈ Training Curves

### πŸ”½ Loss

![Training vs Validation Loss](notebooks/images/loss_plot.png)

### πŸ”Ό Accuracy

![Training vs Validation Accuracy](notebooks/images/accuracy_plot.png)

> _Outputs were stripped using pre-commit to keep this repo clean._

---

## 🧠 Reflections

Despite strong training performance, the validation metrics suggest overfitting. This provides a clear path to improvement:

- βœ… Add dropout layers
- βœ… Use weight decay
- βœ… Apply data augmentation (`RandomCrop`, `HorizontalFlip`)
- βœ… Explore more expressive architectures or learning rate schedulers

---

## βœ… Pre-Commit Enabled

![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=flat-square&logo=pre-commit)

This project uses [`pre-commit`](https://pre-commit.com/) to ensure:
- Clean `.ipynb` notebooks (`nbstripout`)
- Consistent code style (`black`, `isort`)
- Valid YAML + JSON
- No trailing whitespace or newline issues

To install:

```bash
pip install pre-commit
pre-commit install