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
+
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 |
+

|
| 37 |
+

|
| 38 |
+

|
| 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 |
+

|
| 50 |
+

|
| 51 |
+

|
| 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 |
+

|
| 89 |
+

|
| 90 |
+
|
| 91 |
+
## What the CNN learns
|
| 92 |
+
|
| 93 |
+
**Feature maps before vs. after training**
|
| 94 |
+
|
| 95 |
+

|
| 96 |
+

|
| 97 |
+
|
| 98 |
+
**First-layer filters before vs. after training**
|
| 99 |
+
|
| 100 |
+

|
| 101 |
+

|
| 102 |
+
|
| 103 |
+
**Grad-CAM: where the network looks**
|
| 104 |
+
|
| 105 |
+

|
| 106 |
+

|
| 107 |
+
|
| 108 |
+
**Confidence and mistakes**
|
| 109 |
+
|
| 110 |
+

|
| 111 |
+

|
| 112 |
+

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