ChandraPrakashBathula commited on
Commit
e625897
Β·
verified Β·
1 Parent(s): c1ca17b

Create Readme.md

Browse files
Files changed (1) hide show
  1. Readme.md +134 -0
Readme.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Intel Scene CNN
3
+ emoji: πŸ”οΈ
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 5.9.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ # Intel Scene Classification: a CNN built from scratch
14
+
15
+ A plain convolutional neural network (no ResNet, no pretrained weights) trained on the
16
+ [Intel Image Classification](https://www.kaggle.com/datasets/puneet6060/intel-image-classification)
17
+ dataset: ~25k natural scene photos in 6 classes: **buildings, forest, glacier, mountain, sea, street**.
18
+
19
+ This is the follow-up to my EuroSAT satellite CNN. It tests whether the same architecture
20
+ generalizes to street-level photos, where orientation matters and the classes overlap visually.
21
+
22
+ **Live demo:** upload an image, get the predicted class and a Grad-CAM heatmap, plus the test metrics.
23
+
24
+ ## Results
25
+
26
+ | Metric | Value |
27
+ |---|---|
28
+ | Test accuracy (seg_test, 3,000 images) | **XX.X%** |
29
+ | Macro F1 | **0.XXX** |
30
+ | Best validation accuracy | **XX.X%** |
31
+ | Parameters | **~1.21M** |
32
+
33
+ Main confusions: **buildings ↔ street** and **glacier ↔ mountain ↔ sea** (snow, rock and water look alike).
34
+ Several of the "confident mistakes" are actually labeling errors in the dataset.
35
+
36
+ ![Confusion matrix](images/11_confusion_matrix.png)
37
+ ![Per-class accuracy](images/12_per_class_accuracy.png)
38
+ ![Training curves](images/10_curves.png)
39
+
40
+ ## Dataset
41
+
42
+ | Split | Images |
43
+ |---|---|
44
+ | seg_train β†’ train (85%) | ~11,900 |
45
+ | seg_train β†’ validation (15%, stratified) | ~2,100 |
46
+ | seg_test (held-out test) | 3,000 |
47
+ | seg_pred (unlabeled) | ~7,300 |
48
+
49
+ ![Samples](images/01_samples.png)
50
+ ![Class distribution](images/02_class_distribution.png)
51
+ ![Average color per class](images/03_class_colors.png)
52
+
53
+ ## Architecture
54
+
55
+ ```mermaid
56
+ flowchart LR
57
+ A[Input 3Γ—128Γ—128] --> B1[Block 1<br/>32ch β†’ 64Γ—64]
58
+ B1 --> B2[Block 2<br/>64ch β†’ 32Γ—32]
59
+ B2 --> B3[Block 3<br/>128ch β†’ 16Γ—16]
60
+ B3 --> B4[Block 4<br/>256ch β†’ 8Γ—8]
61
+ B4 --> G[Global Avg Pool<br/>256]
62
+ G --> F1[Dropout 0.4 β†’ FC 128 β†’ ReLU]
63
+ F1 --> F2[FC 6 β†’ softmax]
64
+ ```
65
+
66
+ Each block is `Conv3Γ—3 β†’ BN β†’ ReLU β†’ Conv3Γ—3 β†’ BN β†’ ReLU β†’ MaxPool 2Γ—2 β†’ Dropout2d(0.1)`.
67
+
68
+ | Stage | Output shape |
69
+ |---|---|
70
+ | Input | 3 Γ— 128 Γ— 128 |
71
+ | Block 1 | 32 Γ— 64 Γ— 64 |
72
+ | Block 2 | 64 Γ— 32 Γ— 32 |
73
+ | Block 3 | 128 Γ— 16 Γ— 16 |
74
+ | Block 4 | 256 Γ— 8 Γ— 8 |
75
+ | Global average pool | 256 |
76
+ | FC + ReLU | 128 |
77
+ | FC (logits) | 6 |
78
+
79
+ ## Training setup
80
+
81
+ - **Optimizer:** AdamW (lr 1e-3, weight decay 1e-2), cosine LR schedule, 30 epochs
82
+ - **Loss:** cross-entropy with label smoothing 0.1
83
+ - **Image size:** 128Γ—128, normalized with per-channel stats computed from the training data
84
+ - **Augmentation:** random resized crop (0.75–1.0), horizontal flip, Β±10Β° rotation, mild color jitter
85
+ - **No vertical flips or large rotations.** Scenes have gravity (sky on top), unlike satellite images.
86
+ - **Model selection:** best validation accuracy checkpoint
87
+
88
+ ![Augmentation](images/04_augmentation.png)
89
+ ![Bad augmentation](images/05_bad_augmentation.png)
90
+
91
+ ## What the CNN learns
92
+
93
+ **Feature maps before vs. after training**
94
+
95
+ ![Before](images/06_feature_maps_before.png)
96
+ ![After](images/08_feature_maps_after.png)
97
+
98
+ **First-layer filters before vs. after training**
99
+
100
+ ![Filters before](images/07_filters_before.png)
101
+ ![Filters after](images/09_filters_after.png)
102
+
103
+ **Grad-CAM: where the network looks**
104
+
105
+ ![Grad-CAM](images/15_gradcam.png)
106
+ ![Grad-CAM on mistakes](images/16_gradcam_mistakes.png)
107
+
108
+ **Confidence and mistakes**
109
+
110
+ ![Confidence](images/13_confidence.png)
111
+ ![Mistakes](images/14_mistakes.png)
112
+ ![Unlabeled predictions](images/17_unlabeled_predictions.png)
113
+
114
+ ## Run locally
115
+
116
+ ```bash
117
+ pip install -r requirements.txt gradio
118
+ python app.py
119
+ ```
120
+
121
+ ## Files
122
+
123
+ | File | Purpose |
124
+ |---|---|
125
+ | `app.py` | Gradio app: upload, prediction, Grad-CAM, metrics, plots |
126
+ | `model.py` | `SceneCNN` architecture + Grad-CAM |
127
+ | `cnn_intel.pth` | Trained weights (state_dict) |
128
+ | `cnn_intel_meta.json` | Class names, normalization stats, width, image size |
129
+ | `metrics.json` | Test metrics shown in the app |
130
+ | `images/` | All plots from training and evaluation |
131
+
132
+ ## Author
133
+
134
+ Chandra Prakash Bathula, Adjunct Faculty, Saint Louis University (School for Professional Studies)