This repository contains the implementation of an automated marker detection system using YOLO (You Only Look Once) for analyzing soil displacement in large-scale shaking table tests. The system detects and tracks markers on soil surfaces to measure displacement during seismic simulations.
If you use this code in your research, please cite:
@article{zafar2025automated,
title={Automated Marker Detection Using YOLO for Soil Displacement Analysis in Large-Scale Shaking Table Tests},
author={Zafar, A.},
journal={Intelligence, Informatics and Infrastructure},
volume={6},
number={3},
pages={137--149},
year={2025}
}This project implements a computer vision pipeline for:
- Marker Detection: Automated detection of markers on soil surfaces using YOLO (YOLOv5, YOLOv7, YOLOv8)
- Displacement Calculation: Measurement of marker displacement between before/after images
- Data Augmentation: Synthetic data generation using GANs and geometric transformations to prevent data leakage
- Evaluation: Comprehensive metrics including Pearson correlation, MAE, and SSIM
surface_displacement/
βββ calc_displacement.py # Main displacement calculation script
βββ compare_template_vs_yolo.py # Template matching vs YOLO comparison
βββ coordinates.py # Coordinate extraction utilities
βββ check_duplicates.py # Duplicate detection script
βββ yolo/ # YOLOv5 implementation and data
β βββ calc_displacement.py # YOLO-based displacement calculation
β βββ evaluate_metrics.py # Evaluation metrics
β βββ heatmaps.py # Displacement heatmap visualization
β βββ fig6.py, fig7.py # Figure generation scripts
β βββ marker_yolo/ # YOLO dataset (synthetic/augmented images)
β βββ aug_bank/ # Augmented image bank
β βββ results_mapped/ # Mapped displacement results
βββ yolov7/ # YOLOv7 implementation
β βββ yolov7/ # YOLOv7 source code
β βββ yolov7_data/ # Training data
β βββ aug_bank/ # Augmented images
βββ yolov8/ # YOLOv8 implementation
βββ prevent_data_leakage/ # Cross-validation setup
β βββ case3/, case4/, case5/, case6/ # Per-case folders
β β βββ synth/images/ # GAN-generated synthetic images
β β βββ images/train/ # Training images
β β βββ images/val/ # Validation images
β β βββ labels/ # YOLO format labels
β βββ scripts/ # Data preparation scripts
βββ tables/ # Results tables
βββ figures/ # Generated figures
- Python 3.7 or higher
- PyTorch 1.7 or higher
- CUDA (optional, for GPU acceleration)
- Clone the repository:
git clone https://github.com/yourusername/surface_displacement.git
cd surface_displacement- Install dependencies:
pip install -r requirements.txt- For YOLOv5, install from the subdirectory:
cd yolo/yolov5
pip install -r requirements.txt
cd ../..- For YOLOv7, install from the subdirectory:
cd yolov7
pip install -r requirements.txt
cd ..cd yolo/yolov5
python train.py --img 1920 --batch 16 --epochs 100 --data ../data.yaml --weights yolov5m.ptcd yolov7
python yolov7/train.py --img 1920 --batch 16 --epochs 100 --data data.yaml --weights yolov7.ptRun detection on images:
python yolo/yolov5/yolov5/detect.py --weights runs/train/exp/weights/best.pt --source path/to/imagesCalculate displacement between before/after image pairs:
python calc_displacement.pyThis script:
- Loads trained YOLO model
- Detects markers in before/after image pairs
- Matches markers using nearest neighbor (KD-tree)
- Converts pixel displacements to millimeters
- Saves results to
results/directory
Evaluate model performance:
python yolo/evaluate_metrics.pyGenerate displacement heatmaps:
python yolo/heatmaps.pyThe prevent_data_leakage/ directory contains scripts for cross-validation setup:
# Setup fold for case3 (holdout)
cd prevent_data_leakage
python scripts/setup_fold.py case3
# Generate synthetic images from training cases
python scripts/tmp_make_synth_from_training_cases.py --src case3/gan_train_input --out case3/synth/images --n 400
# Generate train/val split from synthetic images
python scripts/gen_split_from_synth.py case3- Uses YOLO object detection models (YOLOv5, YOLOv7, YOLOv8)
- Trained on synthetic and augmented images
- Single class detection: "marker"
- Detect markers in before and after images
- Match markers using nearest neighbor algorithm (KD-tree)
- Calculate pixel displacement
- Convert to real-world units (millimeters) using calibration
- Synthetic Images: GAN-generated images from training cases
- Geometric Augmentation: Rotation, flipping, affine transformations
- Photometric Augmentation: Brightness, contrast, noise, JPEG compression
- 4-fold cross-validation (Case3, Case4, Case5, Case6)
- Each case held out for testing
- Training on remaining cases + synthetic data
The system achieves displacement measurement with:
- Pearson Correlation: Varies by case (see
tables/displacement_metrics_summary.csv) - Mean Absolute Error (MAE): 27-47 mm depending on case
- SSIM: Structural similarity metrics for displacement fields
Note: This repository does not include:
- Original test images (confidential)
- Actual ground truth measurements (confidential)
Included:
- Synthetic/GAN-generated images
- Augmented images
- Training/validation splits
- Processed results and figures
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- YOLOv5: Ultralytics
- YOLOv7: WongKinYiu
- YOLOv8: Ultralytics
For questions or inquiries, please open an issue or contact the repository maintainer.
Disclaimer: The actual test images and measurements are not included in this repository due to confidentiality. The code and synthetic data are provided for reproducibility and research purposes.