Steel ROI Gate Training
This project now supports a steel-surface detector in front of defect segmentation.
Why detector and not plain classifier?
- A classifier can say
steelornon_steel, but it cannot give the bounding box you asked for. - A detector can localize the steel region, crop that ROI, and send only that region into the defect segmentation model.
- This is the right architecture for mixed live-camera scenes with people, tools, and background clutter.
What the scripts do
prepare_surface_gate_dataset.py
- downloads steel-positive sources automatically
- downloads non-steel backgrounds automatically
- creates a YOLO detector dataset
- generates synthetic composites so the detector learns actual steel bounding boxes
- writes
dataset.yaml
train_surface_gate_detector.py
- finetunes a small YOLO detector quickly
- copies the best checkpoint into
models/steel_surface_detector.pt - makes the web app use that model automatically after restart
Automatic data sources
Positive steel sources:
- NEU mirror on Hugging Face
- local
test_images/ - optional Severstal mirror on Hugging Face
Automatic non-steel/background source:
torchvisiondatasets downloaded automatically- default quick path:
CIFAR10 - optional stronger but heavier path:
STL10
This avoids making you manually collect a non-steel dataset.
Recommended quick workflow
- Install training extras:
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy"
venv/bin/python -m pip install -r training/requirements.txt
- Build the detector dataset:
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy"
venv/bin/python training/prepare_surface_gate_dataset.py
This default mode is the fastest path because it avoids the larger Severstal archive and uses CIFAR10 as an automatic non-steel source.
If you want stronger natural-scene negatives later:
venv/bin/python training/prepare_surface_gate_dataset.py --negative-source stl10
If you want a stronger detector after the first run, rebuild with Severstal included:
venv/bin/python training/prepare_surface_gate_dataset.py --include-severstal
- Train the lightweight detector:
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy"
venv/bin/python training/train_surface_gate_detector.py
- Restart the app:
cd "/Users/ravindranadhm/Documents/Projects/steel-surface-inspection copy"
venv/bin/uvicorn api.main:app --host 127.0.0.1 --port 8000
Fast settings
If you want the quickest useful first model:
model=yolo11n.ptepochs=18imgsz=512batch=16- dataset build without
--include-severstal
If you have only CPU and want to finish faster:
venv/bin/python training/train_surface_gate_detector.py --epochs 12 --imgsz 416 --batch 8
If you want a stronger detector later
- increase
--max-severstal - increase
--max-negatives - raise
--composite-multiplier - train
25-40epochs instead of12-18
Runtime config after training
The app will automatically use:
models/steel_surface_detector.pt
Relevant env keys are already supported:
SURFACE_DETECTOR_PATHSURFACE_DETECTOR_CLASS_NAMESURFACE_DETECTOR_CONFIDENCESURFACE_DETECTOR_MIN_AREA_RATIOSURFACE_DETECTOR_EXPAND_RATIOSURFACE_DETECTOR_IMAGE_SIZE
Important expectation
The first fast model is meant to be a practical gate, not a perfect production vision model.
The improvement loop should be:
- train the quick detector
- deploy it
- save false accepts / false rejects from live camera
- add those hard examples back into training
- retrain
That is the fastest route to a reliable factory-facing steel ROI gate.