Skip to content

dinraj910/Structural-Damage-Severity-Assessment-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typing SVG

Status License PRs Welcome Maintained


OverviewFeaturesArchitectureQuick StartDemoTech StackPerformanceRoadmapContributingLicense




🎯 Overview

💡 What It Does

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.

🌍 Why It Matters

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.


🏷️ Damage Severity Classes

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



✨ Features

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



🏗️ Architecture

🧠 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  │
  │              │     │                  │     │                  │
  └──────────────┘     └──────────────────┘     └──────────────────┘



🔬 Technical Deep Dive

📐 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:

  1. Extracting activations from conv5_block3_out (the last ResNet50 conv block)
  2. Computing gradients of the predicted class w.r.t. these activations
  3. Global-average-pooling gradients to obtain per-filter importance weights
  4. Combining weighted activations into a spatial heatmap
  5. 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 .keras model 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 model



📁 Project Structure

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



🚀 Quick Start

📋 Prerequisites

Requirement Version Purpose
Python 3.10+ Runtime
pip Latest Package management
Git Any Repository cloning
GPU (optional) CUDA 11.8+ Accelerated inference

📥 Installation

# ── 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.txt

▶️ Run the Application

streamlit run app.py

The app launches at http://localhost:8501 — upload a building image and get instant results.




🖥️ Screenshots

� Application Interface

🏠 Landing Page
Clean, informative interface explaining the model, classes, and architecture

Landing Page
📤 Upload Interface
Drag & drop image upload with sidebar controls

Upload Interface

🔮 Prediction Results

📊 Classification Results
Severity prediction with confidence scores and probability breakdown

Classification Results
📈 Confidence Breakdown
Per-class probability bars with color-coded severity levels

Confidence Breakdown

🔍 Grad-CAM Explainability

🎯 Activation Heatmap
Raw Grad-CAM heatmap showing decision-driving regions

Activation Heatmap
🌈 Grad-CAM Overlay
Heatmap overlaid on original image with adjustable opacity

Grad-CAM Overlay

🔬 Advanced Features

⚙️ Interactive Controls
Sidebar options and explainability settings

Interactive Controls
📋 Complete Analysis
Full end-to-end damage assessment workflow

Complete Analysis



⚙️ Configuration

Streamlit Theme (.streamlit/config.toml)

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

Environment Variables

Variable Required Default Description
MODEL_PATH model/structural_damage_cnn.keras Custom model file path



🛠️ Tech Stack

Layer Technology Role
Python 3.10+ Core language
TensorFlow 2.15 Deep learning framework
Keras High-level model API
OpenCV Image processing & Grad-CAM overlay
NumPy Numerical computation
Streamlit Web application framework
🖼️ Pillow Image decoding & manipulation
📊 Matplotlib Visualisation support

🧠 Skills Demonstrated

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



📈 Performance

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.




🗺️ Roadmap

 ✅ 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



☁️ Cloud Deployment

🚀 Deploy to Streamlit Cloud (Free)
  1. Push this repository to GitHub
  2. Visit share.streamlit.io
  3. Connect your GitHub repo
  4. Select app.py as the entry point
  5. Deploy — dependencies install automatically from requirements.txt

⚠️ Ensure model/structural_damage_cnn.keras is 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-assessment



🤝 Contributing

Contributions 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

📜 Contribution Guidelines

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



⚠️ Disclaimer

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.




📄 License

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.



👤 Author

DINRAJ K DINESH

Deep Learning Engineer · Computer Vision Researcher


GitHub LinkedIn Email




🙏 Acknowledgements

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



⭐ Star History

Star History Chart




💖 Show Your Support

If this project helped you, please consider giving it a ⭐!

GitHub stars

⭐ Star this repo · 🍴 Fork it · 🐛 Report bugs · 💡 Request features


Built with ❤️ and TensorFlow — Making structures safer, one prediction at a time.

About

A production-ready web application that deploys a Convolutional Neural Network for automated visual assessment of structural damage in building photographs. This AI-assisted tool can screen thousands of structures in minutes, guiding human inspectors to the most critical cases first.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors