π₯ PyTorch β Complete Deep Learning Repository
π§ A complete hands-on PyTorch deep learning repository covering
everything from tensor operations and autograd to CNNs, RNNs, LSTMs,
Transfer Learning, GPU training, and hyperparameter optimization
with Optuna β built through real projects on Fashion MNIST dataset.
π Complete Topics Index
#
Notebook
Topic
Level
1
1_Tensors_in_Pytorch.ipynb
Tensors β creation, ops, GPU
π’ Beginner
2
pytorch_autograd.ipynb
Autograd & Backpropagation
π’ Beginner
3
dataset_and_dataloader_demo.ipynb
Custom Dataset & DataLoader
π‘ Intermediate
4
pytorch_training_pipeline.ipynb
Basic Training Pipeline
π‘ Intermediate
5
pytorch_training_pipeline_using_dataset_...ipynb
Training Pipeline + DataLoader
π‘ Intermediate
6
pytorch_training_pipeline_using_nn_mod...ipynb
Training Pipeline + nn.Module
π‘ Intermediate
7
ann_fashion_mnist_pytorch_gpu.ipynb
ANN on Fashion MNIST β GPU
π Advanced
8
ann_fashion_mnist_pytorch_gpu_optimiz...ipynb
ANN + BatchNorm + Dropout
π Advanced
9
ann_fashion_mnist_pytorch_gpu_optimiz...ipynb
ANN + Optuna Hyperparameter Tuning
π΄ Expert
10
cnn_fashion_mnist_pytorch_gpu.ipynb
CNN on Fashion MNIST β GPU
π Advanced
11
cnn_optuna.ipynb
CNN + Optuna Tuning
π΄ Expert
12
pytorch_lstm_next_word_predictor.ipynb
LSTM β Next Word Prediction
π΄ Expert
13
pytorch_rnn_based_qa_system.ipynb
RNN β Question Answering System
π΄ Expert
14
transfer_learning_fashion_mnist_pytorch...ipynb
Transfer Learning β ResNet18
π΄ Expert
File
Description
fmnist_small.csv
Fashion MNIST dataset (13MB)
100_Unique_QA_Dataset.csv
Custom QA dataset for RNN system
import torch
# Create tensors
t = torch .tensor ([[1 , 2 ], [3 , 4 ]], dtype = torch .float32 )
# GPU support
device = "cuda" if torch .cuda .is_available () else "cpu"
t = t .to (device )
# Operations
print (t .shape ) # torch.Size([2, 2])
print (t @ t ) # Matrix multiplication
print (t .mean ()) # Mean
print (t .reshape (- 1 )) # Flatten
x = torch .tensor (3.0 , requires_grad = True )
y = x ** 2 + 2 * x + 1
y .backward () # Backpropagation
print (x .grad ) # dy/dx = 2x+2 = 8.0
# Always zero grad before next step
optimizer .zero_grad ()
loss .backward ()
optimizer .step ()
3. π¦ Custom Dataset & DataLoader
from torch .utils .data import Dataset , DataLoader
import pandas as pd
class FashionDataset (Dataset ):
def __init__ (self , csv_file ):
self .data = pd .read_csv (csv_file )
def __len__ (self ):
return len (self .data )
def __getitem__ (self , idx ):
label = self .data .iloc [idx , 0 ]
pixels = self .data .iloc [idx , 1 :].values / 255.0
return torch .tensor (pixels , dtype = torch .float32 ), label
dataset = FashionDataset ("fmnist_small.csv" )
loader = DataLoader (dataset , batch_size = 32 , shuffle = True )
4. ποΈ Training Pipeline β nn.Module
import torch .nn as nn
class NeuralNet (nn .Module ):
def __init__ (self , input_size , hidden_size , num_classes ):
super ().__init__ ()
self .network = nn .Sequential (
nn .Linear (input_size , hidden_size ),
nn .BatchNorm1d (hidden_size ),
nn .ReLU (),
nn .Dropout (0.3 ),
nn .Linear (hidden_size , num_classes )
)
def forward (self , x ):
return self .network (x )
# Training loop
model = NeuralNet (784 , 256 , 10 ).to (device )
criterion = nn .CrossEntropyLoss ()
optimizer = torch .optim .Adam (model .parameters (), lr = 0.001 )
for epoch in range (20 ):
for X_batch , y_batch in loader :
X_batch = X_batch .to (device )
y_batch = y_batch .to (device )
optimizer .zero_grad ()
loss = criterion (model (X_batch ), y_batch )
loss .backward ()
optimizer .step ()
5. πΌοΈ CNN on Fashion MNIST (GPU)
class CNN (nn .Module ):
def __init__ (self ):
super ().__init__ ()
self .conv_block = nn .Sequential (
nn .Conv2d (1 , 32 , kernel_size = 3 , padding = 1 ),
nn .BatchNorm2d (32 ),
nn .ReLU (),
nn .MaxPool2d (2 , 2 ),
nn .Conv2d (32 , 64 , kernel_size = 3 , padding = 1 ),
nn .BatchNorm2d (64 ),
nn .ReLU (),
nn .MaxPool2d (2 , 2 )
)
self .fc_block = nn .Sequential (
nn .Flatten (),
nn .Linear (64 * 7 * 7 , 256 ),
nn .ReLU (),
nn .Dropout (0.4 ),
nn .Linear (256 , 10 )
)
def forward (self , x ):
return self .fc_block (self .conv_block (x ))
6. π― Optuna β Hyperparameter Tuning
import optuna
def objective (trial ):
lr = trial .suggest_float ("lr" , 1e-4 , 1e-2 , log = True )
hidden = trial .suggest_categorical ("hidden" , [128 , 256 , 512 ])
dropout = trial .suggest_float ("dropout" , 0.2 , 0.5 )
batch_size = trial .suggest_categorical ("batch_size" , [32 , 64 , 128 ])
model = NeuralNet (784 , hidden , 10 ).to (device )
# ... training loop with above params ...
return val_accuracy
study = optuna .create_study (direction = "maximize" )
study .optimize (objective , n_trials = 50 )
print ("Best params:" , study .best_params )
print ("Best accuracy:" , study .best_value )
7. π LSTM β Next Word Predictor
class LSTMModel (nn .Module ):
def __init__ (self , vocab_size , embed_dim , hidden_dim , num_layers ):
super ().__init__ ()
self .embedding = nn .Embedding (vocab_size , embed_dim )
self .lstm = nn .LSTM (
embed_dim , hidden_dim ,
num_layers = num_layers ,
batch_first = True ,
dropout = 0.3
)
self .fc = nn .Linear (hidden_dim , vocab_size )
def forward (self , x , hidden = None ):
x = self .embedding (x )
out , hidden = self .lstm (x , hidden )
return self .fc (out [:, - 1 , :]), hidden
8. π€ RNN β QA System
# Uses 100_Unique_QA_Dataset.csv
class RNNQAModel (nn .Module ):
def __init__ (self , vocab_size , embed_dim , hidden_dim ):
super ().__init__ ()
self .embedding = nn .Embedding (vocab_size , embed_dim )
self .rnn = nn .GRU (
embed_dim , hidden_dim ,
batch_first = True ,
bidirectional = True
)
self .fc = nn .Linear (hidden_dim * 2 , vocab_size )
def forward (self , x ):
x = self .embedding (x )
out , _ = self .rnn (x )
return self .fc (out [:, - 1 , :])
9. π Transfer Learning β ResNet18
import torchvision .models as models
# Load pretrained ResNet18
model = models .resnet18 (pretrained = True )
# Freeze all layers
for param in model .parameters ():
param .requires_grad = False
# Replace final layer for 10 classes
model .fc = nn .Sequential (
nn .Linear (model .fc .in_features , 256 ),
nn .ReLU (),
nn .Dropout (0.3 ),
nn .Linear (256 , 10 )
)
model = model .to (device )
# Only final layer trains β fast & efficient
Model
Dataset
Accuracy
Key Technique
ANN Basic
Fashion MNIST
~87%
GPU Training
ANN Optimized
Fashion MNIST
~88%
BatchNorm + Dropout
ANN + Optuna
Fashion MNIST
~89%
Hyperparameter Tuning
CNN GPU
Fashion MNIST
~91%
Conv2d + MaxPool
CNN + Optuna
Fashion MNIST
~92%+
Full HP Optimization
Transfer Learning
Fashion MNIST
~93%+
ResNet18 Pretrained
Component
Technology
Deep Learning
PyTorch 2.x
GPU Training
CUDA
HP Tuning
Optuna
Datasets
Fashion MNIST Β· Custom QA CSV
Models
ANN Β· CNN Β· RNN Β· LSTM
Transfer Learning
torchvision ResNet18
Notebooks
Jupyter / Google Colab
# Clone the repo
git clone https://github.com/tashfeen786/PyTorch.git
cd PyTorch
# Install dependencies
pip install torch torchvision jupyter optuna pandas numpy matplotlib
# Check GPU
python -c " import torch; print(torch.cuda.is_available())"
# Launch notebooks
jupyter notebook
ποΈ Project Structure
PyTorch/
β
βββ π Foundations
β βββ 1_Tensors_in_Pytorch.ipynb
β βββ pytorch_autograd.ipynb
β
βββ π¦ Data Handling
β βββ dataset_and_dataloader_demo.ipynb
β βββ fmnist_small.csv # Fashion MNIST (13MB)
β βββ 100_Unique_QA_Dataset.csv # Custom QA dataset
β
βββ ποΈ Training Pipelines
β βββ pytorch_training_pipeline.ipynb
β βββ pytorch_training_pipeline_using_dataset_...ipynb
β βββ pytorch_training_pipeline_using_nn_mod...ipynb
β
βββ π§ ANN Projects
β βββ ann_fashion_mnist_pytorch_gpu.ipynb
β βββ ann_fashion_mnist_pytorch_gpu_optimiz...ipynb
β βββ ann_fashion_mnist_pytorch_gpu_optimiz...ipynb β Optuna
β
βββ πΌοΈ CNN Projects
β βββ cnn_fashion_mnist_pytorch_gpu.ipynb
β βββ cnn_optuna.ipynb
β
βββ π Sequential Models
β βββ pytorch_lstm_next_word_predictor.ipynb
β βββ pytorch_rnn_based_qa_system.ipynb
β
βββ π Transfer Learning
βββ transfer_learning_fashion_mnist_pytorch...ipynb
π Real-World Connection
Skill Learned
Applied In
CNN + GPU
HelmetEye FYP β YOLOv12 based
Custom DataLoader
ML pipeline projects
Transfer Learning
Production CV systems
LSTM / RNN
Sequence modeling & NLP
Optuna Tuning
Model optimization in production
Tashfeen Aziz β AI/ML Engineer & Python Developer
β If you found this helpful, please give it a star!