File size: 2,848 Bytes
6336ad8
0faddb0
6336ad8
 
 
 
0faddb0
6336ad8
0faddb0
 
6336ad8
 
0faddb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
title: CIFAR-10 Vision Transformer Classifier
emoji: 👀
colorFrom: purple
colorTo: pink
sdk: docker
app_port: 7860
pinned: false
license: mit
short_description: Classify images into 10 CIFAR-10 .
---

# 🔍 CIFAR-10 Vision Transformer Classifier

A web-based image classification application powered by a **custom Vision Transformer (ViT)** trained from scratch on the **CIFAR-10** dataset. Upload any image and get real-time predictions across 10 categories.

---

## 🚀 Demo

Upload any image via drag-and-drop or file browser. The model resizes it to **32×32 pixels** (the native CIFAR-10 resolution) and predicts one of 10 classes with confidence scores.

**Supported Classes:**
`airplane` · `automobile` · `bird` · `cat` · `deer` · `dog` · `frog` · `horse` · `ship` · `truck`

---

## 🧠 Model Architecture

| Component | Details |
|-----------|---------|
| Architecture | Vision Transformer (ViT) — built from scratch |
| Patch Size | 4 × 4 pixels |
| Embedding Dim | 256 |
| Transformer Depth | 20 layers |
| Attention Heads | 8 |
| MLP Dim | 512 |
| Total Parameters | ~10.57 Million |
| Input Size | 32 × 32 × 3 |
| Output Classes | 10 |

### Training Details

| Metric | Value |
|--------|-------|
| Dataset | CIFAR-10 (50K train / 10K test) |
| Epochs | 25 |
| Training Accuracy | 72.59% |
| Test Accuracy | **70.51%** |

---

## 🛠️ Tech Stack

- **Backend:** Flask (Python)
- **ML Framework:** PyTorch
- **Frontend:** HTML5 · Vanilla CSS · JavaScript
- **Model:** Custom Vision Transformer (no pretrained weights)
- **Containerization:** Docker

---

## 📁 Project Structure

```
├── flask_app.py          # Flask server (routes: /, /predict, /model-info)
├── cifar10_model.pth     # Trained model weights
├── requirements.txt      # Python dependencies
├── Dockerfile            # Container configuration
└── templates/
    └── index.html        # Full-featured web UI
```

---

## ⚙️ Run Locally

```bash
# 1. Install dependencies
pip install -r requirements.txt

# 2. Start the Flask server
python flask_app.py

# 3. Open in browser
# → http://127.0.0.1:5000
```

---

## 🐳 Run with Docker

```bash
# Build the image
docker build -t cifar10-vit .

# Run the container
docker run -p 7860:7860 cifar10-vit

# Open in browser
# → http://localhost:7860
```

---

## 📊 Features

- 🖼️ **Drag & Drop upload** — supports JPEG, PNG, WEBP, BMP
- 🔲 **32×32 pixel simulator** — see exactly what the model processes
- 📊 **Animated probability bars** for all 10 classes
- ⚡ **Real-time inference** with latency display (milliseconds)
- 🎨 **Warm beige premium UI** with glassmorphism cards

---

## 👤 Author

**Nausad Ali**  
Built with ❤️ and a Cup of Coffee

---

## 📄 License

This project is licensed under the **MIT License**.