MyTorch is a lightweight neural‑network framework built from scratch in Python. It provides the core building blocks for constructing, training, and evaluating deep‑learning models without relying on PyTorch internals.
Tensor: n‑dimensional array with support for automatic gradient tracking, in-place operations, broadcasting, and backpropagation.
- ReLU (
relu.py) - Leaky ReLU (
leaky_relu.py) - Sigmoid (
sigmoid.py) - Tanh (
tanh.py) - Softmax (
softmax.py) - Step Function (
step.py)
- Linear (fully connected) (
linear.py) - Conv2D (
conv2d.py) - Pooling
- MaxPool2D (
max_pool2d.py) - AvgPool2D (
avg_pool2d.py)
- MaxPool2D (
- Generic Layer Interface (
layer.py) - High‑level Model API (
model.py): assemble and manage layers, forward pass orchestration.
- Mean Squared Error (MSE) (
mse.py) - Binary Cross‑Entropy (BCE) (
bce.py) - Categorical Cross‑Entropy (CE) (
ce.py)
- SGD (
sgd.py) - Momentum (
momentum.py) - RMSProp (
rmsprop.py) - Adam (
adam.py)
All optimizers follow a uniform Optimizer interface defined in optimizer.py.
- Custom DataLoader (
my_data_loader.py): mini‑batch iteration, shuffling, parallel loading support - Utility Data Loader (
util/data_loader.py) - Flatten helper for reshaping tensors (
util/flatten.py) - Weight & Bias Initializers (
util/initializer.py)
Five Jupyter notebooks demonstrate both native PyTorch models and their MyTorch counterparts across two datasets:
-
Task 1 (PyTorch MLP)
Build and train a multilayer perceptron in PyTorch. -
Task 2 (MyTorch MLP)
Re‑implement the same MLP using MyTorch’s Tensor, Module and SGD classes.
Demonstrates end‑to‑end custom backpropagation.
-
Task 3 (PyTorch MLP)
Benchmark MLP on FER‑2013 images (flattened input). -
Task 4 (PyTorch CNN)
Build and train a convolutional network in PyTorch for emotion classification. -
Task 5 (MyTorch CNN)
Re‑implement the CNN architecture in MyTorch, covering Conv2D, pooling and softmax layers.
Illustrates how MyTorch handles multi‑dimensional gradient flow.