Image Classification
Keras
LiteRT
TF-Keras
Safetensors
English
efficientnetv2-s
efficientnetv2
fgic
transfer-learning
gem-pooling
focal-loss
swa
grad-cam
calibration
temperature-scaling
computer-vision
tensorflow.js
Eval Results (legacy)
Instructions to use 0xgr3y/Arch-Building-Image-Classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use 0xgr3y/Arch-Building-Image-Classification with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://0xgr3y/Arch-Building-Image-Classification") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -13,14 +13,11 @@ tags:
|
|
| 13 |
- calibration
|
| 14 |
- temperature-scaling
|
| 15 |
- computer-vision
|
| 16 |
-
-
|
| 17 |
library_name: keras
|
| 18 |
language: en
|
| 19 |
datasets:
|
| 20 |
- 0xgr3y/arch-building-dataset
|
| 21 |
-
widget:
|
| 22 |
-
- src: results/greyscope-labs-architecture-classification-efficientnetv2.jpg
|
| 23 |
-
example_title: Bridge Classification
|
| 24 |
model-index:
|
| 25 |
- name: Architectural Building Image Classifier
|
| 26 |
results:
|
|
@@ -82,10 +79,14 @@ A fine-grained image classification model for world architectural buildings. Bui
|
|
| 82 |
|
| 83 |
- **GeM Pooling** (Radenovic et al., CVPR 2018) β replaces global average pooling with a learnable power parameter (p=3.0) that emphasizes high-activation features, yielding stronger discriminative representations for FGIC tasks
|
| 84 |
- **Focal Loss** (Lin et al., ICCV 2017, gamma=2.0) β down-weights well-classified examples to focus gradient updates on hard-to-classify building pairs
|
| 85 |
-
- **DiscriminativeAdamW LR** β extends AdamW with per-variable LR scaling on block6 (Γ0.1) via update_step override, combined with selective fine-tuning (block6+top_conv unfrozen, BN frozen). LR scaling produces truly discriminative updates β block6 variables receive 10Γ smaller learning rate than head variables
|
| 86 |
-
- **
|
| 87 |
-
- **
|
|
|
|
|
|
|
|
|
|
| 88 |
- **ECE Calibration** (Guo et al., ICML 2017) β Expected Calibration Error with 15-bin reliability diagram to assess prediction confidence reliability
|
|
|
|
| 89 |
|
| 90 |
## Architecture
|
| 91 |
|
|
@@ -142,7 +143,7 @@ Output (8 classes)
|
|
| 142 |
| Top-2 Accuracy | 99.26% |
|
| 143 |
| Top-3 Accuracy | 99.70% |
|
| 144 |
| Macro ROC-AUC (OvR) | 0.9985 |
|
| 145 |
-
| ECE (15 bins) | 0.1204 (pre-T-scaling
|
| 146 |
|
| 147 |
### Per-Class Results
|
| 148 |
|
|
@@ -169,21 +170,25 @@ Four candidate models were evaluated on the validation set:
|
|
| 169 |
| `fine_tuning_ema.keras` | 93.53% | 0.6007 | Phase 2 EMA (per-step Polyak averaging) |
|
| 170 |
| **`fine_tuning_swa.keras`** | **98.36%** | **0.4109** | **SWA averaged weights β SELECTED** |
|
| 171 |
|
| 172 |
-
###
|
| 173 |
-
|
| 174 |
-
|
|
| 175 |
-
|-----------|-------------|----------|
|
| 176 |
-
| 1 |
|
| 177 |
-
| 2 |
|
| 178 |
-
|
|
| 179 |
-
|
|
| 180 |
-
|
|
| 181 |
-
|
|
| 182 |
-
|
|
| 183 |
-
|
|
| 184 |
-
|
|
| 185 |
-
|
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |

|
| 189 |
|
|
@@ -191,16 +196,12 @@ Four candidate models were evaluated on the validation set:
|
|
| 191 |
|
| 192 |

|
| 193 |
|
| 194 |
-

|
| 197 |
|
| 198 |

|
| 199 |
|
| 200 |

|
| 201 |
|
| 202 |
-

|
| 203 |
-
|
| 204 |
## Training Details
|
| 205 |
|
| 206 |
### Training Strategy
|
|
@@ -245,12 +246,12 @@ Two-phase progressive training with SWA post-processing:
|
|
| 245 |
| Transfer Learning | EfficientNetV2-S backbone frozen in Phase 1 | Yosinski et al., NeurIPS 2014 |
|
| 246 |
| Selective Fine-Tuning | Unfreeze block6+top_conv only, BN stays frozen | Howard & Ruder, ACL 2018 |
|
| 247 |
| Discriminative LR Scaling | block6 LRΓ0.1 via update_step (truly discriminative β 10Γ smaller updates for pretrained features) | Howard & Ruder, ACL 2018 |
|
| 248 |
-
| CutMix + Mixup | Alternation per batch (50/50), Phase 1 only | Yun et al., ICCV 2019
|
| 249 |
| Focal Loss | gamma=2.0, down-weights easy examples | Lin et al., ICCV 2017 |
|
| 250 |
| Label Smoothing | 0.1 (Phase 1) β 0.05 (Phase 2) | Szegedy et al., CVPR 2016 |
|
| 251 |
| GeM Pooling | p=3.0 learnable, replaces GAP | Radenovic et al., CVPR 2018 |
|
| 252 |
| Dropout | 0.4 after Dense(256)+BN | Srivastava et al., JMLR 2014 |
|
| 253 |
-
| Batch Normalization | After Conv2D and Dense
|
| 254 |
| EMA (per-step) | Shadow weights, decay=0.999, Polyak averaging | Tarvainen & Valpola, NeurIPS 2017 |
|
| 255 |
| SWA | 10-epoch post-training, constant LR 1e-4 | Izmailov et al., UAI 2018 |
|
| 256 |
| Data Augmentation | Rotation Β±15Β°, shift Β±10%, shear Β±0.1 rad, zoom Β±20%, brightness 0.75β1.15, channel shift Β±10.0, horizontal flip | Perez & Wang, arXiv 2017 |
|
|
@@ -273,7 +274,7 @@ See the dataset curation page for [World Architectural Buildings Dataset for Mul
|
|
| 273 |
|
| 274 |
- **Normalization:** `preprocess_input` from `tf.keras.applications.efficientnet_v2` (ImageNet distribution)
|
| 275 |
- **Input resolution:** 320Γ320 (higher than ImageNet default 224Γ224 to capture fine-grained architectural details β textures, ornaments, facade patterns)
|
| 276 |
-
- **Augmentation:** Applied to training set only
|
| 277 |
- **Split method:** `splitfolders.ratio` from `dataset/`, seed=42
|
| 278 |
|
| 279 |
## Files
|
|
@@ -285,14 +286,14 @@ See the dataset curation page for [World Architectural Buildings Dataset for Mul
|
|
| 285 |
| **Config** | `config.json` Β· `label_mapping.json` Β· `preprocessor_config.json` |
|
| 286 |
| **Evaluation** | `calibration_data.json` Β· `model_benchmark.json` Β· `confusion_pairs.json` Β· `class_confidence_stats.json` Β· `temperature_config.json` |
|
| 287 |
| **Deployment** | `saved_model/` (183 MB) Β· `tflite/` (88 MB) Β· `tfjs_model/` (90 MB, 23 shards) |
|
| 288 |
-
| **Results** | `results/` β 12 PNG (training curves, confusion matrix, ROC, t-SNE, Grad-CAM, etc.) |
|
| 289 |
| **Archive** | `models_keras/` β 3 checkpoints (head_training, fine_tuning, fine_tuning_ema) |
|
| 290 |
|
| 291 |
## Usage
|
| 292 |
|
| 293 |
### Gradio Space
|
| 294 |
|
| 295 |
-
Try the live building
|
| 296 |
|
| 297 |
### Python β build_model.py (recommended)
|
| 298 |
|
|
@@ -459,6 +460,8 @@ Keras vs TFLite consistency was verified on 8 random test samples (1 per class):
|
|
| 459 |
|
| 460 |
> The 1 misclassification (castleβbarn, 65% confidence) is consistent with the 97.77% test accuracy. The 8/8 match confirms TFLite conversion preserves model behavior exactly.
|
| 461 |
|
|
|
|
|
|
|
| 462 |
## Security Notice (PAIT-KERAS-301)
|
| 463 |
|
| 464 |
The `.keras` files in this repository are flagged **"Unsafe"** by [Protect AI Guardian](https://protectai.com/insights/models/0xgr3y/Arch-Building-Image-Classification) (threat: PAIT-KERAS-301). This is a **structural false positive**, not a malware detection:
|
|
@@ -487,7 +490,7 @@ With model is provided in multiple formats to suit different deployment scenario
|
|
| 487 |
| **Weights H5** β | `fine_tuning_swa.weights.h5` | ~158 MB | β Safe | β | Programmatic load via `build_model.py` |
|
| 488 |
| **safetensors** β | `fine_tuning_swa.safetensors` | ~157 MB | β Safe | β | HF standard, cross-framework |
|
| 489 |
| **Build Script** β | `build_model.py` | ~21 KB | β Safe | β | Architecture reconstruction + `load_weights()` |
|
| 490 |
-
| **Keras**
|
| 491 |
|
| 492 |
### Load Examples
|
| 493 |
|
|
@@ -504,7 +507,7 @@ See **Usage** section above for complete load + inference examples for each form
|
|
| 504 |
|
| 505 |
- Trained on Pexels stock photography β performance may differ on user-generated or field photographs
|
| 506 |
- Limited to 8 architectural classes (barn, bridge, castle, mosque, skyscraper, stadium, temple, windmill)
|
| 507 |
-
- Confusion pair analysis found **0 significant pairs** (threshold >5%) β all 8 classes are well-distinguished by the model
|
| 508 |
- Barn and windmill share 3 cross-class duplicates (0.02% of dataset) β left as-is due to negligible impact
|
| 509 |
- Inference confidence can be low on atypical examples
|
| 510 |
|
|
@@ -522,7 +525,7 @@ See **Usage** section above for complete load + inference examples for each form
|
|
| 522 |
|
| 523 |
- **Gradio Space (Live):** [arch-building-classifier Space](https://huggingface.co/spaces/0xgr3y/arch-building-classifier)
|
| 524 |
- **Dataset Studio:** [0xgr3y/arch-building-dataset](https://huggingface.co/datasets/0xgr3y/arch-building-dataset)
|
| 525 |
-
- **GitHub
|
| 526 |
|
| 527 |
## References
|
| 528 |
|
|
|
|
| 13 |
- calibration
|
| 14 |
- temperature-scaling
|
| 15 |
- computer-vision
|
| 16 |
+
- tensorflow.js
|
| 17 |
library_name: keras
|
| 18 |
language: en
|
| 19 |
datasets:
|
| 20 |
- 0xgr3y/arch-building-dataset
|
|
|
|
|
|
|
|
|
|
| 21 |
model-index:
|
| 22 |
- name: Architectural Building Image Classifier
|
| 23 |
results:
|
|
|
|
| 79 |
|
| 80 |
- **GeM Pooling** (Radenovic et al., CVPR 2018) β replaces global average pooling with a learnable power parameter (p=3.0) that emphasizes high-activation features, yielding stronger discriminative representations for FGIC tasks
|
| 81 |
- **Focal Loss** (Lin et al., ICCV 2017, gamma=2.0) β down-weights well-classified examples to focus gradient updates on hard-to-classify building pairs
|
| 82 |
+
- **DiscriminativeAdamW LR** β extends AdamW with per-variable LR scaling on block6 (Γ0.1) via (update_step) override, combined with selective fine-tuning (block6+top_conv unfrozen, BN frozen). LR scaling produces truly discriminative updates β block6 variables receive 10Γ smaller learning rate than head variables (117 total: 105 block6 + 12 head)
|
| 83 |
+
- **Mixup + CutMix** (Zhang et al., ICLR 2018. Yun et al., ICCV 2019) β alternating per-batch (50/50): Mixup (alpha=0.2, linear interpolation) and CutMix (alpha=1.0, spatial patch). Applied only in Phase 1 training to regularize head learning
|
| 84 |
+
- **Selective Unfreeze** (Yosinski et al., 2014) β Phase 2 unfreezes block6+top_conv layers (180/513 EfficientNetV2-S layers) while keeping BatchNormalization frozen to preserve pretrained statistics
|
| 85 |
+
- **SWA with BN re-estimation** (Izmailov et al., UAI 2018) β 10-epoch post-training weight averaging with constant LR 1e-4, followed by 100-step batch normalization statistics re-estimation (3,200 images)
|
| 86 |
+
- **Test-Time Augmentation** β 6 variations averaged at inference: original, horizontal flip, center crop 85%, center crop 70%, corner crop top-left 80%, corner crop bottom-right 80%. Yields +0.22% accuracy improvement (97.77% β 97.99%)
|
| 87 |
+
- **Grad-CAM** (Selvaraju et al., ICCV 2017) β gradient-weighted class activation mapping for explainability, targeting *top_conv* (last Conv2D layer of EfficientNetV2-S)
|
| 88 |
- **ECE Calibration** (Guo et al., ICML 2017) β Expected Calibration Error with 15-bin reliability diagram to assess prediction confidence reliability
|
| 89 |
+
- **Temperature Scaling** (Guo et al., ICML 2017) β post-hoc calibration via scalar temperature parameter T optimized on validation set (NLL minimization). T=0.54 reduces ECE from 12.04% (underconfident due to Label Smoothing) to 0.53% β applied at inference via (softmax(log(probs) / T)) trick
|
| 90 |
|
| 91 |
## Architecture
|
| 92 |
|
|
|
|
| 143 |
| Top-2 Accuracy | 99.26% |
|
| 144 |
| Top-3 Accuracy | 99.70% |
|
| 145 |
| Macro ROC-AUC (OvR) | 0.9985 |
|
| 146 |
+
| ECE (15 bins) | 0.1204 (pre-T-scaling. post-T-scaling: 0.0053, T=0.54) |
|
| 147 |
|
| 148 |
### Per-Class Results
|
| 149 |
|
|
|
|
| 170 |
| `fine_tuning_ema.keras` | 93.53% | 0.6007 | Phase 2 EMA (per-step Polyak averaging) |
|
| 171 |
| **`fine_tuning_swa.keras`** | **98.36%** | **0.4109** | **SWA averaged weights β SELECTED** |
|
| 172 |
|
| 173 |
+
### Training Progression
|
| 174 |
+
|
| 175 |
+
| Phase | Epoch | Train Acc | Val Accuracy | Val Loss |
|
| 176 |
+
|-------|-------|-----------|-------------|----------|
|
| 177 |
+
| Phase 1 (Head Training) | 1 | 56.96% | 92.19% | 1.0079 |
|
| 178 |
+
| Phase 2 (Selective Fine-Tuning) | 1 | 84.96% | 96.21% | 0.5656 |
|
| 179 |
+
| SWA | 1 | 90.83% | 95.76% | 0.5831 |
|
| 180 |
+
| SWA | 2 | 94.07% | 97.62% | 0.5116 |
|
| 181 |
+
| SWA | 3 | 95.36% | 97.69% | 0.4748 |
|
| 182 |
+
| SWA | 4 | 96.56% | 96.95% | 0.4390 |
|
| 183 |
+
| SWA | 5 | 97.18% | 97.47% | 0.4490 |
|
| 184 |
+
| SWA | 6 | 97.76% | 97.84% | 0.4416 |
|
| 185 |
+
| SWA | 7 | 97.91% | 98.14% | 0.4055 |
|
| 186 |
+
| SWA | 8 | 98.19% | 97.32% | 0.4359 |
|
| 187 |
+
| SWA | 9 | 98.14% | 97.02% | 0.4519 |
|
| 188 |
+
| SWA | 10 | 98.59% | 97.54% | 0.4226 |
|
| 189 |
+
| **SWA + BN (final)** | β | β | **98.36%** | **0.4109** |
|
| 190 |
+
|
| 191 |
+
> Phase 1 and Phase 2 each stopped after 1 epoch via `myCallback` (custom early stopping at target accuracy: 85% Phase 1, 92% Phase 2). SWA ran 10 epochs with constant LR 1e-4, followed by BN re-estimation (100 steps, 3,200 images). Values shown are training-time metrics from progress bar. checkpoint evaluation values may differ slightly (see Model Selection table above).
|
| 192 |
|
| 193 |

|
| 194 |
|
|
|
|
| 196 |
|
| 197 |

|
| 198 |
|
| 199 |
+

|
|
|
|
|
|
|
| 200 |
|
| 201 |

|
| 202 |
|
| 203 |

|
| 204 |
|
|
|
|
|
|
|
| 205 |
## Training Details
|
| 206 |
|
| 207 |
### Training Strategy
|
|
|
|
| 246 |
| Transfer Learning | EfficientNetV2-S backbone frozen in Phase 1 | Yosinski et al., NeurIPS 2014 |
|
| 247 |
| Selective Fine-Tuning | Unfreeze block6+top_conv only, BN stays frozen | Howard & Ruder, ACL 2018 |
|
| 248 |
| Discriminative LR Scaling | block6 LRΓ0.1 via update_step (truly discriminative β 10Γ smaller updates for pretrained features) | Howard & Ruder, ACL 2018 |
|
| 249 |
+
| CutMix + Mixup | Alternation per batch (50/50), Phase 1 only | Yun et al., ICCV 2019. Zhang et al., ICLR 2018 |
|
| 250 |
| Focal Loss | gamma=2.0, down-weights easy examples | Lin et al., ICCV 2017 |
|
| 251 |
| Label Smoothing | 0.1 (Phase 1) β 0.05 (Phase 2) | Szegedy et al., CVPR 2016 |
|
| 252 |
| GeM Pooling | p=3.0 learnable, replaces GAP | Radenovic et al., CVPR 2018 |
|
| 253 |
| Dropout | 0.4 after Dense(256)+BN | Srivastava et al., JMLR 2014 |
|
| 254 |
+
| Batch Normalization | After Conv2D and Dense. frozen during fine-tuning | Ioffe & Szegedy, arXiv 2015 |
|
| 255 |
| EMA (per-step) | Shadow weights, decay=0.999, Polyak averaging | Tarvainen & Valpola, NeurIPS 2017 |
|
| 256 |
| SWA | 10-epoch post-training, constant LR 1e-4 | Izmailov et al., UAI 2018 |
|
| 257 |
| Data Augmentation | Rotation Β±15Β°, shift Β±10%, shear Β±0.1 rad, zoom Β±20%, brightness 0.75β1.15, channel shift Β±10.0, horizontal flip | Perez & Wang, arXiv 2017 |
|
|
|
|
| 274 |
|
| 275 |
- **Normalization:** `preprocess_input` from `tf.keras.applications.efficientnet_v2` (ImageNet distribution)
|
| 276 |
- **Input resolution:** 320Γ320 (higher than ImageNet default 224Γ224 to capture fine-grained architectural details β textures, ornaments, facade patterns)
|
| 277 |
+
- **Augmentation:** Applied to training set only. validation and test sets use clean preprocessing
|
| 278 |
- **Split method:** `splitfolders.ratio` from `dataset/`, seed=42
|
| 279 |
|
| 280 |
## Files
|
|
|
|
| 286 |
| **Config** | `config.json` Β· `label_mapping.json` Β· `preprocessor_config.json` |
|
| 287 |
| **Evaluation** | `calibration_data.json` Β· `model_benchmark.json` Β· `confusion_pairs.json` Β· `class_confidence_stats.json` Β· `temperature_config.json` |
|
| 288 |
| **Deployment** | `saved_model/` (183 MB) Β· `tflite/` (88 MB) Β· `tfjs_model/` (90 MB, 23 shards) |
|
| 289 |
+
| **Results** | `results/` β 12 PNG (augmentation, reliability-diagram, training curves, confusion matrix, ROC, t-SNE, Grad-CAM, etc.) |
|
| 290 |
| **Archive** | `models_keras/` β 3 checkpoints (head_training, fine_tuning, fine_tuning_ema) |
|
| 291 |
|
| 292 |
## Usage
|
| 293 |
|
| 294 |
### Gradio Space
|
| 295 |
|
| 296 |
+
Try the live building classify: [Architecture Building Image Classifier with Space](https://huggingface.co/spaces/0xgr3y/arch-building-classifier)
|
| 297 |
|
| 298 |
### Python β build_model.py (recommended)
|
| 299 |
|
|
|
|
| 460 |
|
| 461 |
> The 1 misclassification (castleβbarn, 65% confidence) is consistent with the 97.77% test accuracy. The 8/8 match confirms TFLite conversion preserves model behavior exactly.
|
| 462 |
|
| 463 |
+

|
| 464 |
+
|
| 465 |
## Security Notice (PAIT-KERAS-301)
|
| 466 |
|
| 467 |
The `.keras` files in this repository are flagged **"Unsafe"** by [Protect AI Guardian](https://protectai.com/insights/models/0xgr3y/Arch-Building-Image-Classification) (threat: PAIT-KERAS-301). This is a **structural false positive**, not a malware detection:
|
|
|
|
| 490 |
| **Weights H5** β | `fine_tuning_swa.weights.h5` | ~158 MB | β Safe | β | Programmatic load via `build_model.py` |
|
| 491 |
| **safetensors** β | `fine_tuning_swa.safetensors` | ~157 MB | β Safe | β | HF standard, cross-framework |
|
| 492 |
| **Build Script** β | `build_model.py` | ~21 KB | β Safe | β | Architecture reconstruction + `load_weights()` |
|
| 493 |
+
| **Keras** βΉ | `fine_tuning_swa.keras` | ~227 MB | βΉ Flagged | 358.0 ms | Developer reference, fine-tuning |
|
| 494 |
|
| 495 |
### Load Examples
|
| 496 |
|
|
|
|
| 507 |
|
| 508 |
- Trained on Pexels stock photography β performance may differ on user-generated or field photographs
|
| 509 |
- Limited to 8 architectural classes (barn, bridge, castle, mosque, skyscraper, stadium, temple, windmill)
|
| 510 |
+
- Confusion pair analysis found **0 significant pairs** (threshold >5%) β all 8 classes are well-distinguished by the model. see `confusion_pairs.json` for details
|
| 511 |
- Barn and windmill share 3 cross-class duplicates (0.02% of dataset) β left as-is due to negligible impact
|
| 512 |
- Inference confidence can be low on atypical examples
|
| 513 |
|
|
|
|
| 525 |
|
| 526 |
- **Gradio Space (Live):** [arch-building-classifier Space](https://huggingface.co/spaces/0xgr3y/arch-building-classifier)
|
| 527 |
- **Dataset Studio:** [0xgr3y/arch-building-dataset](https://huggingface.co/datasets/0xgr3y/arch-building-dataset)
|
| 528 |
+
- **GitHub Repository:** [arcxteam/building-architectural-image-classifier](https://github.com/arcxteam/building-architectural-image-classifier)
|
| 529 |
|
| 530 |
## References
|
| 531 |
|