A structured collection of deep learning projects implemented from scratch in PyTorch. This repository documents a hands-on learning journey through core architectures and training paradigms, from basic MLPs to Neural Style Transfer and Transformers.
- From scratch implementation: No
torchvision.models, every layer written manually - Understanding over results: Focus on learning PyTorch mechanics, not just accuracy
- Clean code: Modular, reusable, and well-documented
- Progressive complexity: Each project introduces new concepts that build on the previous
Content image rendered with Van Gogh's brushstrokes and color palette by optimizing pixel values directly — no training involved, just gradient descent on the image itself.
| # | Project | Dataset | Key Concepts | Result | Status |
|---|---|---|---|---|---|
| 1 | MLP on MNIST | MNIST | Autograd, training loops, DataLoaders | 98.3% accuracy | ✅ Complete |
| 2 | CNN on CIFAR-10 | CIFAR-10 | Convolutions, BatchNorm, Dropout | 86.3% accuracy | ✅ Complete |
| 3 | Neural Style Transfer | Custom images | VGG feature extraction, Gram matrices, image optimization | Artistic image synthesis | ✅ Complete |
| 4 | Transformer for Sentiment | IMDb | Self-attention, positional encoding, NLP | TBD | 🚧 In Progress |
| 5 | VAE | CelebA | Generative models, latent spaces | TBD | 📋 Planned |
# Clone the repository
git clone https://github.com/monex00/pytorch-fundamental.git
cd pytorch-fundamental
# Install dependencies
pip install -r requirements.txt- Python 3.8+
- PyTorch 2.0+ (nightly build recommended for RTX 40/50 series GPUs)
- CUDA (optional but recommended)
# For newer GPUs (RTX 40/50 series - Blackwell/Ada architecture)
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu128pytorch-fundamentals/
│
├── shared/ # Shared utilities across projects
│ └── utils/
│ └── trainer.py # Reusable training and validation loops
│
├── 01_mlp_mnist/ # MLP on MNIST
│ ├── models/mlp.py
│ ├── notebooks/train.ipynb
│ └── results/
│
├── 02_cnn_cifar10/ # CNN on CIFAR-10
│ ├── models/
│ │ ├── lenet.py
│ │ └── custom_cnn.py
│ ├── notebooks/train.ipynb
│ └── results/
│
├── 03_style_transfer/ # Neural Style Transfer
│ ├── models/vgg_extractor.py
│ ├── utils/losses.py
│ ├── notebooks/style_transfer.ipynb
│ ├── images/
│ │ ├── content/
│ │ └── style/
│ └── results/
│
└── 04_transformer_sentiment/ # Transformer for Sentiment Analysis (WIP)
- Computational graphs and autograd
- Custom
nn.Moduleimplementations - DataLoader and Dataset pipelines
- Training and validation loops
- Device management (CPU/GPU)
- Model evaluation and metrics
- Multi-Layer Perceptrons (MLP)
- Convolutional Neural Networks (CNN)
- VGG-style deep networks (as feature extractor)
- Transformers and self-attention
- Variational Autoencoders (VAE)
- Diffusion Models
- Batch Normalization
- Dropout regularization
- Gram matrix for style representation
- Image optimization (optimizing inputs, not weights)
- Transfer learning with frozen networks
- Learning rate scheduling
- Early stopping and model checkpointing
- Data augmentation
"How does PyTorch actually compute gradients?"
The first project strips everything to the essentials: a simple feedforward network trained on MNIST. Focus is entirely on understanding the training loop, how loss.backward() populates gradients, and why optimizer.zero_grad() matters.
Main takeaway: Autograd builds a computational graph on every forward pass. Backprop traverses it backwards, computing ∂loss/∂param for every learnable parameter.
"Why do convolutions outperform MLPs on images?"
Two architectures — the classic LeNet-5 and a modern VGG-style CustomCNN — trained side by side. The 22-point accuracy gap (64% → 86%) makes the impact of BatchNorm, deeper networks, and proper regularization immediately visible.
Main takeaway: Architectural choices matter more than hyperparameters. BatchNorm + Dropout + depth = dramatically better generalization.
"What if we optimize the image instead of the weights?"
A completely different paradigm: VGG19 is frozen, and we run gradient descent on the pixels themselves. Content is matched by comparing deep feature activations; style is matched by comparing Gram matrices (feature correlations).
Main takeaway: Pre-trained networks are versatile feature extractors. Backprop can optimize any differentiable variable — not just weights.
"How does a model learn which words to pay attention to?"
Self-attention mechanism built from scratch, applied to sentiment analysis on IMDb reviews. Multi-head attention, positional encodings, and residual connections all implemented manually.
- PyTorch Official Docs
- PyTorch Tutorials
- Attention Is All You Need (Vaswani et al., 2017)
- A Neural Algorithm of Artistic Style (Gatys et al., 2015)
- Deep Learning Book (Goodfellow et al.)
MIT License - Free to use for learning purposes.
Author: monex00
Last Updated: May 2026
Each project folder contains a detailed README with architecture specifics, results, implementation notes, and lessons learned.
