Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌉 Bridge Defect Image Detection and Classification

A CNN-based image classification project that automatically detects and classifies bridge surface defects using deep learning.


📋 Project Overview

This project implements a deep learning pipeline to classify bridge surface defects into 6 categories using Convolutional Neural Networks (CNN). Two models are trained and compared:

  • Custom CNN — built from scratch with 4 convolutional blocks
  • MobileNetV2 — transfer learning with ImageNet pretrained weights
Model Validation Accuracy Parameters Pretrained
Custom CNN 49.90% 720,806 No
MobileNetV2 66.60% 2,588,486 Yes (ImageNet)

🗂️ Dataset

Dataset: MultiClassifier Bridge Defect Dataset
Total Images: 2,411
Classes: 6
Image Size: 224 × 224 pixels (after preprocessing)
Split: 80% Train (1,932) / 20% Validation (479)

Class Images Percentage
Cracks 789 32.7%
No Defect 452 18.7%
Spalling 427 17.7%
Efflorescence 311 12.9%
General 264 10.9%
Scaling 168 7.0%

📁 Repository Structure

bridge-defect-classification/
│
├── main_notebook.ipynb          # Complete Jupyter notebook (all 15 cells)
│
├── multi_classifier_data/       # Dataset folder
│   └── MultiClassifier/
│       ├── cracks/
│       ├── efflorescence/
│       ├── general/
│       ├── no defect/
│       ├── scaling/
│       └── spalling/
│
├── outputs/
│   ├── figures/                 # All saved output figures
│   │   ├── class_distribution.png
│   │   ├── sample_images.png
│   │   ├── cnn_training_curves.png
│   │   ├── cnn_confusion_matrix.png
│   │   ├── mobilenet_training_curves.png
│   │   ├── mobilenet_confusion_matrix.png
│   │   ├── model_comparison.png
│   │   └── gradcam.png
│   └── models/                  # Saved trained models
│       ├── best_cnn.keras
│       └── best_mobilenet.keras
│
└── README.md

⚙️ Setup Instructions

1. Clone the Repository

git clone https://github.com/RohanRaj369/bridge-defect-classification.git
cd bridge-defect-classification

2. Create a Virtual Environment

python3.11 -m venv venv
source venv/bin/activate        # Mac/Linux
# venv\Scripts\activate         # Windows

3. Install Dependencies

pip install tensorflow scikit-learn matplotlib seaborn numpy pillow opencv-python pandas ipykernel jupyter

4. Add the Dataset

Place the dataset inside the project folder so the structure matches:

bridge-defect-classification/
└── multi_classifier_data/
    └── MultiClassifier/
        ├── cracks/
        ├── efflorescence/
        ...

5. Run the Notebook

jupyter notebook main_notebook.ipynb

Or open in VS Code and run cells one by one with Shift+Enter.


🧠 Model Architecture

Custom CNN

Input (224×224×3)
→ Block 1: Conv2D(32) + BN + Conv2D(32) + MaxPool + Dropout
→ Block 2: Conv2D(64) + BN + Conv2D(64) + MaxPool + Dropout
→ Block 3: Conv2D(128) + BN + Conv2D(128) + MaxPool + Dropout
→ Block 4: Conv2D(256) + BN + MaxPool + Dropout
→ GlobalAveragePooling2D
→ Dense(512) + BN + Dropout(0.5)
→ Dense(6, softmax)

MobileNetV2 (Transfer Learning)

Input (224×224×3)
→ MobileNetV2 base (frozen, pretrained on ImageNet)
→ GlobalAveragePooling2D
→ Dense(256) + BatchNorm + Dropout(0.4)
→ Dense(6, softmax)

📊 Results

MobileNetV2 Classification Report

Class Precision Recall F1-Score
Cracks 0.76 0.75 0.75
Efflorescence 0.53 0.68 0.60
General 0.42 0.31 0.36
No Defect 0.88 0.70 0.78
Scaling 0.37 0.52 0.43
Spalling 0.62 0.66 0.64
Weighted Avg 0.66 0.65 0.65

Key Findings

  • MobileNetV2 outperformed Custom CNN by +16.7% accuracy
  • MobileNetV2 converged in just 8 epochs vs 30 for Custom CNN
  • no defect and cracks were the easiest classes to classify
  • general was the hardest class due to visual ambiguity
  • Grad-CAM confirmed the model focuses on crack textures and surface patterns

🖼️ Output Figures

Figure Description
class_distribution.png Bar chart of images per class
sample_images.png Sample grid from all 6 classes
cnn_training_curves.png CNN accuracy & loss over epochs
cnn_confusion_matrix.png CNN confusion matrix
mobilenet_training_curves.png MobileNetV2 accuracy & loss over epochs
mobilenet_confusion_matrix.png MobileNetV2 confusion matrix
model_comparison.png Side-by-side comparison table
gradcam.png Grad-CAM heatmap visualization

🛠️ Technologies Used

  • Python 3.11
  • TensorFlow / Keras 2.21.0
  • scikit-learn — classification report, confusion matrix
  • Matplotlib / Seaborn — visualizations
  • OpenCV — Grad-CAM heatmap overlay
  • Pillow — image loading
  • NumPy / Pandas — data handling

📌 Notebook Structure

Cell Description
1 Import libraries
2 Configuration and dataset path
3 Dataset exploration and class distribution
4 Sample image visualization
5 Preprocessing and data augmentation
6 Custom CNN model architecture
7 Train Custom CNN
8 Plot CNN training curves
9 Evaluate CNN — confusion matrix and report
10 MobileNetV2 transfer learning model
11 Train MobileNetV2
12 Evaluate MobileNetV2
13 Model comparison table
14 Grad-CAM visualization
15 Final summary

👤 Author

Rohan Raj
Machine Learning Course — Phase 2 Project
June 2026


📄 License

This project is submitted as part of an academic course assignment. Dataset credits go to the original dataset creators.

About

CNN-based bridge defect image classification using TensorFlow and MobileNetV2

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages