Vision4Coil
A vision-based system for detecting wire rod coil tails in steel manufacturing using FFT-based temporal gating and instance segmentation. The system identifies informative coil-transition frames via frequency analysis and runs one of three interchangeable deep learning detectors to localise the coil tail.
Repository Structure
Top-level files
| File | Description |
|---|---|
FFT_RTSP.py |
Main processing pipeline β FFT gating + detector integration + sink abstraction |
detectors.py |
Swappable detector classes: YOLODetector, Detectron2Detector, Mask2FormerDetector |
run_on_frames.py |
Batch inference script β runs any detector on a folder of validation frames |
webserver.py |
Flask web server β streams ROI video + FFT graph to a browser dashboard |
requirements.txt |
Python dependencies with install notes for Detectron2 and Mask2Former |
Folders
| Folder | Contents |
|---|---|
model_weights/yolov11/ |
YOLO11 detection weights (best_latest.pt) |
model_weights/detectron2/ |
Detectron2 Mask R-CNN weights (model_final.pth) + config.yaml |
model_weights/mask2former/ |
Mask2Former weights (model_0134999.pth) + config.yaml |
demo_inputs/ |
Sample input video (10-Coils.mov) and validation frames |
demo_outputs/ |
Annotated output images and results.csv per model (generated at runtime) |
Installation
1. Create a clean virtual environment
python3 -m venv vision_env
source vision_env/bin/activate
2. Install PyTorch (match your CUDA version)
# CUDA 12.8 example:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
3. Install core dependencies
pip install opencv-python numpy plotly matplotlib pandas flask ultralytics
4. Install Detectron2
Detectron2 must be built from source. Use --no-build-isolation so the build can find your installed PyTorch:
pip install --no-build-isolation git+https://github.com/facebookresearch/detectron2.git
5. Install Mask2Former
Mask2Former is not pip-installable. Clone it and build the custom CUDA deformable attention ops:
git clone https://github.com/facebookresearch/Mask2Former.git mask2former_repo
cd mask2former_repo/mask2former/modeling/pixel_decoder/ops
python setup.py build install
cd ../../../../..
All scripts that use Mask2Former must be run with:
PYTHONPATH=$PYTHONPATH:mask2former_repo python <script>.py
Running the detectors
Batch inference on validation frames
# YOLO11
python run_on_frames.py --model yolo
# Detectron2 (Mask R-CNN)
PYTHONPATH=$PYTHONPATH:mask2former_repo python run_on_frames.py --model detectron2
# Mask2Former
PYTHONPATH=$PYTHONPATH:mask2former_repo python run_on_frames.py --model mask2former
Optional arguments:
| Argument | Default | Description |
|---|---|---|
--model |
yolo |
Which detector to use (yolo / detectron2 / mask2former) |
--input |
demo_inputs/Validation Dataset |
Folder of input frames |
--output |
demo_outputs/<model> |
Where to save annotated frames + results.csv |
--conf |
0.5 |
Confidence threshold |
--weights |
model-specific default | Override the default weights path |
Annotated frames (mask overlay + bounding box + confidence) and a summary results.csv are written to the output folder.
Swapping detectors in the live pipeline
Edit the bottom of FFT_RTSP.py:
detector = YOLODetector()
# detector = Detectron2Detector()
# detector = Mask2FormerDetector()
Live video / RTSP stream
python FFT_RTSP.py
For a live RTSP camera feed, set credentials at the top of FFT_RTSP.py:
USERNAME = "your_username"
PASSWORD = "your_password"
CAMERA_IP = "192.168.1.100"
Web interface
python webserver.py
# Then open http://localhost:8000
Provides: live ROI video stream, FFT intensity graph, start/stop controls.
FFT Threshold
The FFT intensity threshold separates coil-motion frames from idle frames. Tune per coil type:
THRESHOLD = 4264.8 # DB16
# THRESHOLD = 3200 # R5.5
# THRESHOLD = 3900 # R8.5
Output format
When a segment β₯ 10 s is detected, a timestamped folder is created under output/:
2026_Jul_01-18-22-30_to_18-23-43/
βββ *.txt # Frequency intensity over time (tab-separated)
βββ *.html # Interactive Plotly graph
βββ tail_detected_0.87.jpg # Best frame with mask overlay + bounding box
βββ tail_detected_0.87.json # Detection metadata (class, confidence, bbox)
For batch inference (run_on_frames.py), output goes to demo_outputs/<model>/:
demo_outputs/yolo/
βββ frame001_pred.jpg # Annotated frame
βββ frame002_pred.jpg
βββ results.csv # Per-frame detection results