monarch8661 commited on
Commit
de92012
·
verified ·
1 Parent(s): e9033dd

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +115 -0
README.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ pipeline_tag: image-classification
4
+ tags:
5
+ - heritage
6
+ - temple
7
+ - damage-assessment
8
+ - mixture-of-experts
9
+ - moe
10
+ - resnet50
11
+ - efficientnet-b4
12
+ - vit-base-patch16-224
13
+ - yolo
14
+ license: mit
15
+ metrics:
16
+ - name: test_accuracy
17
+ value: 0.9850
18
+ - name: test_f1_weighted
19
+ value: 0.9853
20
+ library_name: transformers
21
+ ---
22
+
23
+ # Heritage Temple Damage Assessment – Mixture-of-Experts (MoE)
24
+
25
+ ## Model Description
26
+
27
+ This is a **Mixture-of-Experts (MoE)** ensemble for automatically assessing structural damage in heritage temple images. It combines four pre‑trained expert models:
28
+
29
+ - **ResNet50** – texture‑sensitive, good for fine cracks and surface damage.
30
+ - **EfficientNet‑B4** – balanced accuracy/speed, robust to varying image quality.
31
+ - **ViT‑Base (patch16_224)** – captures global context and structural deformations.
32
+ - **YOLO fallback CNN** – a lightweight custom CNN that acts as a robust fallback for heavily corrupted or low‑resolution images.
33
+
34
+ A learned **gating network** dynamically weights the experts’ contributions per image. The final output is one of three damage classes:
35
+
36
+ | Class | Criticality Grade |
37
+ |-------------------|-------------------|
38
+ | Undamaged | STABLE |
39
+ | Partial Damage | MINOR |
40
+ | Damaged | CRITICAL |
41
+
42
+ The model also outputs per‑expert predictions, gate weights, and a continuous confidence score. A fallback chain (gate → uniform ensemble → mock) guarantees robustness in production.
43
+
44
+ ## Intended Uses & Limitations
45
+
46
+ **Intended use**: Automated preliminary damage screening for heritage site managers, conservation architects, and NGOs. The model is designed for images captured by drones, phones, or archival photographs (visible spectrum).
47
+
48
+ **Limitations**:
49
+ - The training set is moderately imbalanced (fewer “Damaged” samples). Performance on rare damage types (e.g., severe spalling) may be lower.
50
+ - The model was trained on a combination of publicly available damage datasets (concrete cracks, disaster infrastructure, surface cracks). It may not generalise equally to all temple architectures (e.g., brick vs. stone).
51
+ - Very low‑resolution (< 224×224) or heavily compressed images degrade accuracy.
52
+ - The model does **not** provide a continuous severity score; only discrete classes (future work).
53
+
54
+ ## Training Data
55
+
56
+ The model was fine‑tuned on a curated dataset of ~4,800 training images aggregated from:
57
+
58
+ - Concrete crack images (classification)
59
+ - Surface crack detection
60
+ - Disaster infrastructure damage (CDD)
61
+ - Building damage assessment datasets
62
+ - QuakeSet (limited, due to access restrictions)
63
+
64
+ Images were resized to 224×224, augmented (random crop, flip, rotate, colour jitter, coarse dropout), and split 70/15/15 for training/validation/test. Class‑weighted sampling and focal loss were used to handle imbalance.
65
+
66
+ ## Training Procedure
67
+
68
+ All experts were initialised with ImageNet‑1k weights and fine‑tuned for 25 epochs (5 frozen backbone, 20 unfrozen). The gating network was trained for 15 epochs on frozen experts, using cross‑entropy + 0.01× load‑balancing loss. Gradient accumulation (effective batch 64), EMA, and mixup were applied. Training was done on a single Tesla T4 GPU (Kaggle).
69
+
70
+ ## Evaluation Results
71
+
72
+ On the held‑out test set (1,028 images):
73
+
74
+ | Metric | Value |
75
+ |-----------------------|---------|
76
+ | Accuracy | 0.9850 |
77
+ | Weighted F1 | 0.9853 |
78
+ | Per‑class F1 (Undamaged) | 0.99 |
79
+ | Per‑class F1 (Partial) | 1.00 |
80
+ | Per‑class F1 (Damaged) | 0.95 |
81
+
82
+ **Expert‑only performance (test F1)**:
83
+ - ResNet50: 0.9467
84
+ - EfficientNet‑B4: 0.9641
85
+ - ViT‑B16: 0.9792
86
+ - YOLO fallback: 0.6278
87
+
88
+ The MoE ensemble outperforms every individual expert, demonstrating the benefit of adaptive weighting.
89
+
90
+ ## How to Use
91
+
92
+ The model is hosted on Hugging Face Hub and requires `trust_remote_code=True` because it includes a custom MoE architecture.
93
+
94
+ ```python
95
+ from transformers import AutoModelForImageClassification
96
+ from PIL import Image
97
+ import requests
98
+
99
+ # Load model from Hub
100
+ model = AutoModelForImageClassification.from_pretrained(
101
+ "monarch8661/moe",
102
+ trust_remote_code=True
103
+ )
104
+
105
+ # Load and preprocess an image
106
+ url = "https://example.com/temple_damage.jpg"
107
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
108
+
109
+ # Run inference (returns a dict with all details)
110
+ outputs = model(image)
111
+ print(outputs["predicted_class"]) # e.g., "Partial Damage"
112
+ print(outputs["criticality"]) # "MINOR"
113
+ print(outputs["confidence"]) # 0.92
114
+ print(outputs["gate_weights"]) # [0.21, 0.45, 0.30, 0.04]
115
+ print(outputs["per_expert"]) # list of expert predictions