File size: 2,942 Bytes
e4896e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language:
- en
metrics:
- accuracy
tags:
- CNN
- NeuralNetwork
---
# CIFAR-10 CNN Image Classifier

A Convolutional Neural Network (CNN) built **from scratch** using **TensorFlow/Keras** to classify images from the CIFAR-10 dataset into 10 object categories.

This project focuses on **understanding CNN design, training stability, regularization, and evaluation**, without using pretrained models or transfer learning.

---

## 🚀 Project Overview

This project demonstrates:

- CNN architecture design from first principles  
- Training and evaluation on the CIFAR-10 dataset  
- Overfitting detection and mitigation  
- Confusion matrix–based error analysis  
- Clean, modular ML project structure  

The goal is to gain **hands-on understanding of deep learning fundamentals**, rather than maximizing benchmark scores.

---

## 🧠 Dataset

**CIFAR-10**

- 60,000 color images (32×32)
- 10 classes:
  - airplane, automobile, bird, cat, deer  
  - dog, frog, horse, ship, truck
- 50,000 training images
- 10,000 test images

---

## 🏗️ Model Architecture

- **3 Convolutional blocks**
  - Conv2D → Batch Normalization → ReLU → MaxPooling
- **Classifier**
  - Dense(256) → Dropout(0.5)
  - Dense(128) → Dropout(0.3)
  - Dense(10 logits)
- Loss handled using `SparseCategoricalCrossentropy(from_logits=True)`

**Total parameters:** ~1.3M

---

## ⚙️ Training Strategy

- Input normalization
- Data augmentation (horizontal flip, rotation, zoom)
- Batch Normalization for stable training
- Dropout for regularization
- Early stopping to prevent overfitting

Training was stopped automatically once validation performance stopped improving.

---

## 📊 Evaluation & Results

- **Best validation accuracy:** ~67%
- Small train–validation gap → good generalization
- Performance analyzed using a **confusion matrix**

Key observations:
- Strong performance on classes like automobile, frog, ship, and truck
- Expected confusion between visually similar classes (cat ↔ dog, deer ↔ horse)
- Confusion matrix used as a diagnostic tool rather than accuracy alone

---

## 🛠️ Installation

```bash
git clone https://github.com/revanthreddy0906/cifar10-cnn-image-classifier.git
cd cifar10-cnn-image-classifier
pip install -r requirements.txt
```
---

**📌 Key Learnings**
--------------------

-   CNNs outperform dense networks for image data

-   Correct data pipelines are critical for stable training

-   Overfitting must be diagnosed using validation metrics

-   Confusion matrices provide deeper insight than accuracy alone

-   Regularization and early stopping are essential for generalization

* * * * *

**📈 Future Improvements**
--------------------------

-   Stronger data augmentation (MixUp / CutOut)

-   Learning rate scheduling

-   Residual connections (ResNet-style blocks)

-   Transfer learning with pretrained backbones

-   Per-class precision and recall analysis