0xgr3y commited on
Commit
f9344ba
Β·
verified Β·
1 Parent(s): 4de62b5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -36
README.md CHANGED
@@ -13,14 +13,11 @@ tags:
13
  - calibration
14
  - temperature-scaling
15
  - computer-vision
16
- - fgvc
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
- - **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
87
- - **Grad-CAM** (Selvaraju et al., ICCV 2017) β€” gradient-weighted class activation mapping for explainability, targeting *top_conv* (last Conv2D layer)
 
 
 
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; post-T-scaling: 0.0053, T=0.54) |
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
- ### SWA Progression
173
-
174
- | SWA Epoch | Val Accuracy | Val Loss |
175
- |-----------|-------------|----------|
176
- | 1 | 95.76% | 0.5831 |
177
- | 2 | 97.62% | 0.5116 |
178
- | 3 | 97.69% | 0.4748 |
179
- | 4 | 96.95% | 0.4390 |
180
- | 5 | 97.47% | 0.4490 |
181
- | 6 | 97.84% | 0.4416 |
182
- | 7 | 98.14% | 0.4055 |
183
- | 8 | 97.32% | 0.4359 |
184
- | 9 | 97.02% | 0.4519 |
185
- | 10 | 97.54% | 0.4226 |
186
- | **SWA + BN (final)** | **98.36%** | **0.4109** |
 
 
 
 
187
 
188
  ![Training Curves](results/training_curves.png)
189
 
@@ -191,16 +196,12 @@ Four candidate models were evaluated on the validation set:
191
 
192
  ![Per-Class Accuracy](results/per_class_accuracy.png)
193
 
194
- ![Reliability Diagram](results/reliability_diagram.png)
195
-
196
- ![ROC Curves](results/roc_curves.png)
197
 
198
  ![t-SNE Embedding](results/tsne_embedding.png)
199
 
200
  ![Grad-CAM Heatmaps](results/gradcam_heatmaps.png)
201
 
202
- ![Confidence Per Class](results/confidence_per_class.png)
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; Zhang et al., ICLR 2018 |
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; frozen during fine-tuning | Ioffe & Szegedy, arXiv 2015 |
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; validation and test sets use clean preprocessing
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 classifier: [Architecture Building Image Classifier with Space](https://huggingface.co/spaces/0xgr3y/arch-building-classifier)
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** ⚠️ | `fine_tuning_swa.keras` | ~227 MB | ⚠️ Flagged | 358.0 ms | Developer reference, fine-tuning |
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; see `confusion_pairs.json` for details
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 Repo:** [arcxteam/building-architectural-image-classifier](https://github.com/arcxteam/building-architectural-image-classifier)
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
  ![Training Curves](results/training_curves.png)
194
 
 
196
 
197
  ![Per-Class Accuracy](results/per_class_accuracy.png)
198
 
199
+ ![Confidence Per Class](results/confidence_per_class.png)
 
 
200
 
201
  ![t-SNE Embedding](results/tsne_embedding.png)
202
 
203
  ![Grad-CAM Heatmaps](results/gradcam_heatmaps.png)
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
+ ![TFLite Inference](results/inference_tflite.png)
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