Overview • Features • Architecture • Quick Start • Demo • Tech Stack • Performance • Roadmap • Contributing • License
|
A production-ready Computer Vision system that classifies building and infrastructure images into four structural damage severity levels using a fine-tuned ResNet50 CNN — deployed as an interactive Streamlit web application with Grad-CAM explainability. |
After natural disasters — earthquakes, hurricanes, floods — rapid structural triage saves lives. Traditional manual assessment requires expert engineers and days of fieldwork. This AI system can screen thousands of structures in minutes, prioritising critical cases for human inspectors and accelerating disaster response. |
| Class | Severity | Icon | Description | Use Case |
|---|---|---|---|---|
0 |
No Damage | ✅ | Structure appears fully intact | Clear for occupancy |
1 |
Minor Damage | Surface-level cracks, cosmetic issues | Monitor & schedule repair | |
2 |
Moderate Damage | 🔶 | Visible structural compromise | Restrict access, urgent repair |
3 |
Severe Damage | 🔴 | Major structural failure or collapse | Evacuate, demolition review |
| Feature | Description | Status |
|---|---|---|
| 📤 Image Upload | Drag & drop JPG/PNG building photos | ✅ |
| 🤖 Real-Time Inference | Instant 4-class severity prediction | ✅ |
| 📊 Confidence Scores | Per-class softmax probability breakdown | ✅ |
| 🔍 Grad-CAM Explainability | Visual heatmap of decision-driving regions | ✅ |
| 🎨 Professional Dark UI | Custom CSS metric cards & probability bars | ✅ |
| ⚡ Cached Model Loading | @st.cache_resource — zero reload latency |
✅ |
| 🧩 Modular Codebase | Clean separation: UI / preprocessing / inference / XAI | ✅ |
| 📘 Interpretation Guide | Built-in confidence thresholds & disclaimers | ✅ |
| ☁️ Cloud-Ready | One-click deploy to Streamlit Cloud | ✅ |
| 🎛️ Interactive Controls | Adjustable Grad-CAM opacity slider | ✅ |
🧠 Model Architecture — ResNet50 Transfer Learning
┌─────────────────────────────────────────────┐
│ INPUT IMAGE │
│ 224 × 224 × 3 (RGB) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ RESNET50 BACKBONE │
│ (ImageNet Pre-trained, Frozen) │
│ │
│ Conv1 ──► Conv2 ──► Conv3 ──► Conv4 ──► │
│ │
│ ──► Conv5 (conv5_block3_out) ◄── Grad-CAM│
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ GLOBAL AVERAGE POOLING 2D │
│ (2048,) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ DENSE (256, ReLU) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ DROPOUT (0.5) │
└─────────────────┬───────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ DENSE (4, Softmax) ──► OUTPUT │
│ │
│ [No Damage, Minor, Moderate, Severe] │
└─────────────────────────────────────────────┘
⚙️ Application Pipeline — End-to-End Flow
┌──────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ │ │ │ │ │
│ USER │────►│ STREAMLIT │────►│ PREPROCESSING │
│ UPLOADS │ │ FRONTEND │ │ │
│ IMAGE │ │ (app.py) │ │ • Decode bytes │
│ │ │ │ │ • Resize 224² │
└──────────────┘ └──────────────────┘ │ • Normalize /255│
│ • Batch expand │
└────────┬─────────┘
│
▼
┌──────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ │ │ │ │ │
│ RESULTS │◄────│ GRAD-CAM │◄────│ CNN MODEL │
│ DISPLAY │ │ EXPLAINABILITY │ │ INFERENCE │
│ │ │ │ │ │
│ • Class │ │ • Heatmap gen │ │ • Forward pass │
│ • Score │ │ • Overlay blend │ │ • Softmax probs │
│ • Heatmap │ │ • Visualization │ │ • argmax class │
│ │ │ │ │ │
└──────────────┘ └──────────────────┘ └──────────────────┘
📐 Preprocessing Pipeline
The image preprocessing mirrors the exact pipeline used during model training:
# 1. Decode uploaded bytes → PIL RGB Image
image = Image.open(BytesIO(raw_bytes)).convert("RGB")
# 2. Resize to model input dimensions
image_resized = image.resize((224, 224), Image.LANCZOS)
# 3. Convert to float32 array & normalize to [0, 1]
img_array = np.asarray(image_resized, dtype=np.float32) / 255.0
# 4. Add batch dimension → (1, 224, 224, 3)
img_array = np.expand_dims(img_array, axis=0)🔥 Grad-CAM Implementation
Grad-CAM (Selvaraju et al., ICCV 2017) produces visual explanations by:
- Extracting activations from
conv5_block3_out(the last ResNet50 conv block) - Computing gradients of the predicted class w.r.t. these activations
- Global-average-pooling gradients to obtain per-filter importance weights
- Combining weighted activations into a spatial heatmap
- Overlaying the heatmap on the original image with adjustable opacity
grad_model = tf.keras.models.Model(
inputs=model.inputs,
outputs=[model.get_layer("conv5_block3_out").output, model.output]
)
with tf.GradientTape() as tape:
conv_outputs, predictions = grad_model(img_array)
class_channel = predictions[:, pred_index]
grads = tape.gradient(class_channel, conv_outputs)
pooled_grads = tf.reduce_mean(grads, axis=(0, 1, 2))
heatmap = conv_outputs[0] @ pooled_grads[..., tf.newaxis]
heatmap = tf.maximum(heatmap, 0) / tf.math.reduce_max(heatmap)⚡ Model Caching Strategy
The model is loaded using Streamlit's @st.cache_resource decorator, which:
- Loads the
.kerasmodel file once at startup - Shares the same model instance across all user sessions
- Eliminates redundant disk I/O and GPU memory allocations
- Persists across Streamlit re-runs (script re-execution)
@st.cache_resource(show_spinner="Loading CNN model …")
def load_model(model_path=None):
model = tf.keras.models.load_model(model_path)
return modelStructural-Damage-Severity-Assessment-CNN/
│
├── 🎯 app.py # Streamlit UI — entry point
├── 📋 requirements.txt # Pinned Python dependencies
├── 📖 README.md # This file
├── 🚫 .gitignore # Git ignore rules
│
├── 🤖 model/
│ └── structural_damage_cnn.keras # Trained ResNet50 weights (~100 MB)
│
├── 🧰 utils/
│ ├── __init__.py # Package exports
│ ├── preprocessing.py # Image decoding, resize, normalize
│ ├── prediction.py # Cached model loader & inference
│ └── gradcam.py # Grad-CAM heatmap & overlay
│
├── 🖼️ assets/
│ ├── icons/ # App icons & branding
│ └── sample_images/ # Example test images
│
├── 📓 notebooks/
│ ├── Structural_Damage_Assessment.ipynb # Full training notebook
│ └── structural_damage_assessment.py # Notebook as script
│
├── 📸 screenshots/ # App screenshots for docs
│
└── 🎨 .streamlit/
└── config.toml # Dark theme & server config
| Requirement | Version | Purpose |
|---|---|---|
| Python | 3.10+ | Runtime |
| pip | Latest | Package management |
| Git | Any | Repository cloning |
| GPU (optional) | CUDA 11.8+ | Accelerated inference |
# ── 1. Clone the repository ──────────────────────────────────────────────────
git clone https://github.com/dinraj910/Structural-Damage-Severity-Assessment-CNN.git
cd Structural-Damage-Severity-Assessment-CNN
# ── 2. Create & activate virtual environment ─────────────────────────────────
python -m venv venv
# Linux / macOS
source venv/bin/activate
# Windows
venv\Scripts\activate
# ── 3. Install dependencies ──────────────────────────────────────────────────
pip install -r requirements.txtstreamlit run app.pyThe app launches at http://localhost:8501 — upload a building image and get instant results.
|
🏠 Landing Page Clean, informative interface explaining the model, classes, and architecture
|
📤 Upload Interface Drag & drop image upload with sidebar controls
|
|
📊 Classification Results Severity prediction with confidence scores and probability breakdown
|
📈 Confidence Breakdown Per-class probability bars with color-coded severity levels
|
|
🎯 Activation Heatmap Raw Grad-CAM heatmap showing decision-driving regions
|
🌈 Grad-CAM Overlay Heatmap overlaid on original image with adjustable opacity
|
|
⚙️ Interactive Controls Sidebar options and explainability settings
|
📋 Complete Analysis Full end-to-end damage assessment workflow
|
| Setting | Value | Description |
|---|---|---|
primaryColor |
#4fc3f7 |
Accent colour (light blue) |
backgroundColor |
#0e1117 |
App background (dark) |
secondaryBackgroundColor |
#1a1a2e |
Sidebar & card background |
textColor |
#e0e0e0 |
Primary text colour |
font |
sans serif |
Typography |
maxUploadSize |
10 MB |
Maximum upload file size |
| Variable | Required | Default | Description |
|---|---|---|---|
MODEL_PATH |
❌ | model/structural_damage_cnn.keras |
Custom model file path |
| Skill Area | Techniques Applied |
|---|---|
| Deep Learning | Transfer Learning, Fine-Tuning, CNNs |
| Computer Vision | Image Classification, Feature Extraction |
| Explainable AI | Grad-CAM, Gradient Visualization |
| Model Deployment | TensorFlow SavedModel, Keras .keras format |
| Web Development | Streamlit, Custom CSS, Responsive Design |
| Software Engineering | Modular Architecture, Caching, Type Hints |
| MLOps | Model Versioning, Cloud Deployment, .gitignore |
| Metric | Value | Notes |
|---|---|---|
| Training Accuracy | ~93% | 10 epochs, ResNet50 frozen backbone |
| Validation Accuracy | ~89% | 20% hold-out split |
| Inference Time | ~120ms | CPU (single image, cached model) |
| Model Size | ~100 MB | ResNet50 + custom head (.keras) |
| Input Resolution | 224 × 224 | RGB, normalised to [0, 1] |
| Output Classes | 4 | Softmax probability distribution |
📝 Metrics are approximate and depend on hardware. GPU inference is significantly faster.
✅ v1.0 🔄 v1.1 🔄 v1.2 🔄 v1.3 🔄 v2.0 🔜 v2.1 🔜 v3.0
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Core │───►│ Batch │───►│ PDF │───►│ Multi │───►│ API │───►│ Mobile │───►│ Edge │
│ App │ │ Upload │ │ Report │ │ Model │ │ Docker │ │Responsive│ │ Deploy │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
🟢 DONE 🔵 PLANNED 🔵 PLANNED 🔵 PLANNED 🔵 PLANNED 🟣 FUTURE 🟣 FUTURE
| Version | Feature | Status |
|---|---|---|
| v1.0 | Core App — Upload, Predict, Grad-CAM | ✅ Done |
| v1.1 | Batch image upload & CSV export | 🔄 Planned |
| v1.2 | Automated PDF damage report generation | 🔄 Planned |
| v1.3 | Multi-model ensemble (ResNet + EfficientNet) | 🔄 Planned |
| v2.0 | REST API + Docker containerisation | 🔄 Planned |
| v2.1 | Mobile-responsive layout | 🔜 Future |
| v3.0 | Edge deployment (TFLite / ONNX) | 🔜 Future |
🚀 Deploy to Streamlit Cloud (Free)
- Push this repository to GitHub
- Visit share.streamlit.io
- Connect your GitHub repo
- Select
app.pyas the entry point - Deploy — dependencies install automatically from
requirements.txt
⚠️ Ensuremodel/structural_damage_cnn.kerasis committed (or use Git LFS for large files).
🐳 Docker Deployment
FROM python:3.10-slim
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]docker build -t structural-damage-assessment .
docker run -p 8501:8501 structural-damage-assessmentContributions are welcome! Here's how:
# 1. Fork the repository
# 2. Create a feature branch
git checkout -b feature/amazing-feature
# 3. Commit your changes
git commit -m "feat: add amazing feature"
# 4. Push to your branch
git push origin feature/amazing-feature
# 5. Open a Pull Request- Follow existing code style and modular architecture
- Add docstrings to all new functions
- Test changes locally before submitting
- Use conventional commit messages (
feat:,fix:,docs:, etc.)
This application is a decision-support tool and does NOT replace professional structural engineering assessments. Predictions are generated by a machine learning model and may be incorrect — particularly for building types, lighting conditions, or architectural styles not represented in the training data. Do not use this system as the sole basis for safety-critical decisions. Always consult a qualified structural engineer.
This project is licensed under the MIT License — see the LICENSE file for details.
MIT License — Copyright (c) 2026
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
| Resource | Citation |
|---|---|
| ResNet50 | He et al., "Deep Residual Learning for Image Recognition" — CVPR 2016 |
| Grad-CAM | Selvaraju et al., "Grad-CAM: Visual Explanations from Deep Networks" — ICCV 2017 |
| Concrete Crack Dataset | Özgenel, Ç.F. — Concrete Crack Images for Classification |
| Hurricane Damage Dataset | Satellite Images of Hurricane Damage — Kaggle |
| Streamlit | Open-source framework for ML application deployment |
| TensorFlow | Google Brain — End-to-end ML platform |
If this project helped you, please consider giving it a ⭐!
⭐ Star this repo · 🍴 Fork it · 🐛 Report bugs · 💡 Request features







