This workflow verifies image inference without adding a dataset, model weight, or generated output to the repository. You provide both the weight and image from trusted local sources.
git clone https://github.com/YfengJ/steel-defect-detection.git
cd steel-defect-detection
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txtOn Windows, activate the environment with:
.venv\Scripts\activatePython 3.10 is the CI baseline. Python 3.11 is also used for the documented Apple Silicon smoke check.
Choose paths outside git for:
- A trusted YOLOv8
.ptweight, such as an officialyolov8n.ptdownload or your own trainedbest.pt. - An image you are allowed to process.
Do not load untrusted PyTorch checkpoint files. A .pt file can contain
serialized Python objects, so its source matters.
Example local layout:
~/steel-defect-local/
├── weights/
│ └── best.pt
└── images/
└── sample.jpg
These files remain outside the repository. Paths under weights/, datasets/,
and runs/ are ignored if you choose to keep local artifacts inside the clone.
Start with CPU because it is the most portable device:
python predict.py \
--model ~/steel-defect-local/weights/best.pt \
--source ~/steel-defect-local/images/sample.jpg \
--device cpu \
--project runs/detect \
--name sample_cpuThe rendered image is written to runs/detect/sample_cpu/. YOLO labels with
confidence values are written under runs/detect/sample_cpu/labels/.
On Apple Silicon, first confirm MPS availability as described in macos.md, then replace the device:
python predict.py \
--model ~/steel-defect-local/weights/best.pt \
--source ~/steel-defect-local/images/sample.jpg \
--device mps \
--project runs/detect \
--name sample_mpsOn an NVIDIA CUDA environment, use a CUDA index:
python predict.py \
--model /path/to/best.pt \
--source /path/to/sample.jpg \
--device 0 \
--project runs/detect \
--name sample_cudaIf MPS or CUDA fails, rerun the same command with --device cpu and include the
full error output in a bug report.
Check the command contract at any time without loading a model:
python predict.py --helpGenerated outputs are disposable and ignored by git:
rm -rf runs/detect/sample_cpu runs/detect/sample_mpsFor dataset-based training, use dataset.md. For common runtime errors, use troubleshooting.md.