Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gas Pipe Detection

AI models for gas pipe detection and segmentation, developed as part of the EXPAND CoRe 1 project.

This repository trains and evaluates a deep learning model that segments gas pipes in images, then derives pipe-level detection metrics (accuracy, precision, recall, F1) on top of the raw pixel-level segmentation.

Overview

The core pipeline:

  1. Loads a custom gas-pipe image dataset (GasPipeDataset) and splits it into train/validation/test sets.
  2. Applies data augmentation (resize, flips, rotation, brightness/contrast jitter, Gaussian blur, normalization) via Albumentations.
  3. Trains a U-Net segmentation model (src/models/unet.py) to predict pipe masks.
  4. Evaluates the trained model across multiple decision thresholds and reports:
    • Segmentation metrics: Dice coefficient, IoU score, pixel accuracy
    • Detection metrics: detection accuracy, precision, recall, F1-score
    • Pixel classification metrics: pixel precision, recall, F1-score
  5. Automatically selects the best threshold (by IoU) and generates a confusion matrix plus qualitative prediction visualizations.

Repository structure

core-pipe-detection/
├── configs/       # Experiment / model configuration files
├── data/          # Dataset location (see Data section)
├── src/
│   ├── datasets/
│   │   └── GasPipeDataset.py   # Custom PyTorch Dataset + train/val split helper
│   ├── models/
│   │   └── unet.py             # U-Net model, training loop, evaluation & plotting utilities
│   ├── logging.py              # Custom logging handler
│   └── parser.py               # Config/argument parser
├── requirements.txt
└── train.py       # Main entry point: train + evaluate the model

Requirements

Install everything with:

pip install -r requirements.txt

Note: A CUDA-capable GPU is strongly recommended for training.

Data

GasPipeDataset expects an image/mask dataset laid out under a single root directory (path configured via dataset.path in your config). The dataset loader automatically creates an 80/20 train/validation split (train_ratio=0.8, fixed random_state=42 for reproducibility). Place your data under the data/ directory, or point the config at your own dataset location.

Configuration

Runs are driven by a config file (see the configs/ folder) parsed via src/parser.py. At minimum, a config should define:

dataset:
  path: /path/to/dataset

model:
  batch_size: 8
  n_epochs: 50
  lr: 0.0001
  checkpoints: /path/to/checkpoints/model.pth

Usage

Train (and evaluate) a model with:

python train.py --config configs/<your_config>.yaml

What happens under the hood:

  • If a checkpoint already exists at config.model.checkpoints, it is loaded; otherwise a new U-Net is created.
  • The model is trained for config.model.n_epochs epochs, and training/validation loss curves plus Dice scores are plotted and saved next to the checkpoint (*_training_history.png).
  • The best checkpoint is reloaded and evaluated across five thresholds (0.5–0.9); per-threshold results are saved to *_threshold_analysis.json.
  • The threshold with the highest IoU is used to generate a confusion matrix (*_confusion_matrix.png) and a qualitative sample of predictions.

Outputs

For a given checkpoint path (e.g. checkpoints/model.pth), training produces:

File Description
model.pth Best model weights
model_training_history.png Train/val loss and validation Dice score curves
model_threshold_analysis.json Segmentation/detection/pixel metrics at each tested threshold
model_confusion_matrix.png Confusion matrix at the best-performing threshold

About

AI models for pipe detection (EXPAND CoRe 1 project)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages