An open source YOLOv8 project for steel surface defect detection, training, validation, inference, and GUI demos.
This repository is a learning-oriented steel surface defect detection project built on YOLOv8. It targets NEU-DET style steel defect datasets and provides a practical workflow for model training, validation, image inference, video inference, and a desktop GUI demo.
It is designed for students, computer vision beginners, and industrial vision learners who want a real, runnable, and maintainable open source project rather than an unmaintained collection of scripts.
Datasets, training outputs, and model weights are not included in this repository. Prepare them locally by following docs/dataset.md.
- Current version:
v0.1.1. - Basic CI syntax and repository hygiene checks are enabled.
- Documentation exists for macOS, dataset preparation, troubleshooting, support, security, and the roadmap.
- Datasets and model weights are not included in the repository; users should prepare them locally.
- Planned next steps include lightweight smoke tests, a sample workflow, a model card template, and clearer GUI error messages.
| Feature | Description |
|---|---|
| Single-image inference | Load one image and visualize detected defect boxes. |
| Batch inference | Process an image folder and generate summary reports. |
| Video inference | Run defect detection on video files or camera streams. |
| Model training | Train YOLOv8 models from the command line or GUI. |
| Model validation | Evaluate trained weights and inspect mAP metrics. |
| GUI demo | Use a ttkbootstrap desktop interface for common workflows. |
steel-defect-detection/
├── ui.py # Desktop GUI built with ttkbootstrap
├── train.py # YOLOv8 training entrypoint
├── predict.py # Image and batch prediction entrypoint
├── val.py # Validation entrypoint
├── video_predict.py # Video inference helper
├── translate.py # VOC XML to YOLO TXT conversion utility
├── dataset.yaml # Dataset configuration
├── requirements.txt # Python dependencies
├── docs/ # Project setup and maintenance docs
├── .github/ # CI, Dependabot, and issue templates
├── datasets/ # Local datasets, ignored by git
├── runs/ # Local training/inference outputs, ignored by git
└── weights/ or *.pt # Local model weights, ignored by git
The default configuration follows the six common NEU-DET steel surface defect classes:
| ID | Class | Meaning |
|---|---|---|
| 0 | crazing |
Fine crack-like surface patterns |
| 1 | inclusion |
Non-metallic inclusion defects |
| 2 | patches |
Irregular surface patches |
| 3 | pitted_surface |
Pitting or corrosion-like marks |
| 4 | rolled-in_scale |
Oxide scale rolled into the surface |
| 5 | scratches |
Linear scratch defects |
- Python 3.10 recommended
- CPU, Apple Silicon MPS, or NVIDIA CUDA
- Windows, Linux, or macOS
macOS users should start with docs/macos.md.
git clone https://github.com/YfengJ/steel-defect-detection.git
cd steel-defect-detection
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/macOS
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txtPrepare these files locally:
- Dataset: see docs/dataset.md
- Weights: download a YOLOv8 pretrained weight such as
yolov8n.pt, or use your own trainedbest.pt
python ui.pyThe GUI includes tabs for image prediction, batch prediction, video inference, training, and validation.
# CPU
python train.py --model yolov8n.pt --data dataset.yaml --epochs 50 --batch 16 --device cpu
# Apple Silicon MPS
python train.py --model yolov8n.pt --data dataset.yaml --epochs 50 --batch 8 --device mps
# NVIDIA CUDA
python train.py --model yolov8n.pt --data dataset.yaml --epochs 50 --batch 16 --device cudapython val.py --model runs/detect/train_result/weights/best.pt --data dataset.yamlpython predict.py --model runs/detect/train_result/weights/best.pt --source path/to/image.jpgThis project can use the NEU Surface Defect Database or another dataset with the same class mapping.
Expected local layout:
datasets/NEU-DET/
├── images/
│ ├── train/
│ ├── val/
│ └── test/
├── labels/
│ ├── train/
│ ├── val/
│ └── test/
└── annotations/
YOLO label files should use:
class_id x_center y_center width height
All coordinates must be normalized to 0.0 to 1.0.
If your annotations are VOC XML files, place them under datasets/NEU-DET/annotations/ and run:
python translate.pyModel weights are intentionally excluded from git. Keep large artifacts locally, in cloud storage, or in GitHub Releases.
Common local choices:
| Weight | Use case |
|---|---|
yolov8n.pt |
Fastest baseline for CPU or small experiments |
yolov8s.pt |
Better speed/accuracy balance |
yolov8m.pt |
Medium experiments when hardware allows |
best.pt |
Your trained defect detector |
Dependabot is enabled for Python dependencies and GitHub Actions. Large dependency jumps are reviewed conservatively because PyTorch, OpenCV, NumPy, and Ultralytics compatibility can be sensitive across platforms.
See RELEASE_NOTES.md for v0.1.1 changes, known limitations, and next plans.
This project is licensed under the AGPL-3.0 License.
YOLOv8 is provided by Ultralytics and follows its upstream license terms.




