Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

striderzz/ML3-CNN-MLP-CIFARMNIST

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
5 Commits
 
 
 
 
 
 

Repository files navigation

Got it — here’s a clean, professional GitHub README.md you can directly drop into your repo for this project 👇 (It’s written to match CS 6375 Project 3 and your notebooks: MLP.ipynb, cnn_final.ipynb.)


# Deep Learning on MNIST and CIFAR-10 (MLP & CNN)

This repository contains my implementation and evaluation of **Multilayer Perceptrons (MLPs)** and **Convolutional Neural Networks (CNNs)** on the **MNIST** and **CIFAR-10** datasets using **PyTorch**.  
This project was completed as **Project 3 for CS 6375: Machine Learning**.

## 📌 Project Objectives
- Implement MLP and CNN models from scratch using PyTorch
- Explore **multiple architectures** with increasing depth
- Perform **validation-based hyperparameter tuning**
- Compare the performance of **MLPs vs CNNs**
- Evaluate final models on held-out **test sets**

The full project specification is provided in the assignment PDF :contentReference[oaicite:0]{index=0}.

---

## 📂 Repository Structure

. ├── MLP.ipynb # Multilayer Perceptron experiments (MNIST & CIFAR-10) ├── cnn_final.ipynb # Convolutional Neural Network experiments ├── project_3.pdf # Official assignment description └── README.md


---

## 🧠 Models Implemented

### 1️⃣ Multilayer Perceptrons (MLP)
MLPs were trained on **flattened images** from both datasets.

Architectures explored:
- **Shallow MLP**: 1 hidden layer (e.g., 128 units)
- **Medium MLP**: 3 hidden layers (e.g., 512 → 256 → 128)
- **Deep MLP**: 5+ hidden layers

### 2️⃣ Convolutional Neural Networks (CNN)
CNNs were trained directly on image tensors.

Architectures explored:
- **Baseline CNN**: 2 convolutional layers + pooling + FC
- **Enhanced CNN**: Batch Normalization + Dropout
- **Deeper CNN**: 3+ convolutional layers with normalization and dropout

---

## ⚙️ Datasets & Preprocessing
- **MNIST** (28×28 grayscale images)
- **CIFAR-10** (32×32 RGB images)

Preprocessing steps:
- Loaded using `torchvision.datasets`
- Pixel normalization applied
- Dataset split into **training / validation / test**
  - MNIST: 50k train / 10k validation
  - CIFAR-10: 45k train / 5k validation

---

## 🔍 Hyperparameter Tuning
For each architecture and dataset, multiple configurations were tested using a validation set.

Tuned parameters:
- Learning rate: `{0.01, 0.001, 0.0001}`
- Batch size: `{32, 64, 128}`
- Optimizer: `SGD`, `Adam`
- Dropout rate: `{0.2, 0.5}`

Instead of exhaustive search, **10–12 meaningful configurations** were explored per architecture.  
The best model was selected based on **validation accuracy**, then retrained on combined training + validation data.

---

## 📊 Results
Results are reported in the same format as required by the assignment:
- Validation Accuracy (± standard deviation)
- Runtime (minutes)
- Final Test Accuracy

Separate result tables were produced for:
- **MNIST**
- **CIFAR-10**

Key observation:
- CNNs significantly outperform MLPs, especially on **CIFAR-10**, due to their ability to capture spatial features.

---

## 🚀 How to Run

### Requirements
```bash
pip install torch torchvision matplotlib numpy

Run MLP Experiments

jupyter notebook MLP.ipynb

Run CNN Experiments

jupyter notebook cnn_final.ipynb

Note: GPU (Google Colab recommended) significantly reduces training time.


📝 Key Takeaways

  • Deeper models do not always guarantee better performance without proper regularization
  • CNNs are far more effective than MLPs for image-based tasks
  • Batch normalization and dropout improve stability and generalization
  • Validation-based tuning is critical for fair model comparison

📚 References

About

PyTorch implementation of Multilayer Perceptrons (MLPs) and Convolutional Neural Networks (CNNs) evaluated on MNIST and CIFAR-10 with validation-based hyperparameter tuning.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.