Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 2.52 KB

File metadata and controls

72 lines (51 loc) · 2.52 KB

MyTorch: A Custom Deep Learning Library

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.

⚙️ Features

1. Tensor

  • Tensor: n‑dimensional array with support for automatic gradient tracking, in-place operations, broadcasting, and backpropagation.

2. Activation Functions

  • ReLU (relu.py)
  • Leaky ReLU (leaky_relu.py)
  • Sigmoid (sigmoid.py)
  • Tanh (tanh.py)
  • Softmax (softmax.py)
  • Step Function (step.py)

3. Layers & Modules

  • Linear (fully connected) (linear.py)
  • Conv2D (conv2d.py)
  • Pooling
    • MaxPool2D (max_pool2d.py)
    • AvgPool2D (avg_pool2d.py)
  • Generic Layer Interface (layer.py)
  • High‑level Model API (model.py): assemble and manage layers, forward pass orchestration.

4. Loss Functions

  • Mean Squared Error (MSE) (mse.py)
  • Binary Cross‑Entropy (BCE) (bce.py)
  • Categorical Cross‑Entropy (CE) (ce.py)

5. Optimizers

  • SGD (sgd.py)
  • Momentum (momentum.py)
  • RMSProp (rmsprop.py)
  • Adam (adam.py)

All optimizers follow a uniform Optimizer interface defined in optimizer.py.

6. Data Handling

  • 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)

📓 Notebooks Overview

Five Jupyter notebooks demonstrate both native PyTorch models and their MyTorch counterparts across two datasets:

Phase 1: Breast Cancer Wisconsin (Diagnostic)

  • 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.

Phase 2: FER‑2013 Facial Expression Recognition

  • 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.