How ak2042/yolo_face_detection works
Purpose and Entry Points
This is a terminal-driven YOLOv8 face-detection pipeline built around the WIDER FACE dataset. Its three operational entry points are dataset preparation, model training, and webcam inference:
• scripts/DownloadAndFormatDataset.py
• scripts/train.sh
• scripts/infer.sh
Dataset Acquisition and Normalization
scripts/DownloadAndFormatDataset.py is the data-ingestion boundary. It downloads WIDER FACE training/validation imagery and annotations, then converts source annotations into YOLO detection labels. It creates the runtime dataset tree under datasets/widerface/ (generated, not versioned in this tree), including train/validation images, labels, and the YOLO dataset YAML.
YOLO Dataset Contract
The generated datasets/widerface/widerface.yaml is the contract between preparation and training. It establishes:
• dataset root: datasets/widerface
• splits: images/train and images/val
• single detection class: face at class ID 0
Annotation conversion must produce normalized YOLO bounding-box labels aligned with each image, since Ultralytics consumes this layout directly.
Training Stage
scripts/train.sh invokes the Ultralytics YOLOv8 CLI to fine-tune a pretrained YOLOv8 nano checkpoint (yolov8n.pt per the README) against the generated dataset. The documented default training profile is 50 epochs at 640×640 resolution. Training outputs, including the selected checkpoint, are expected under Ultralytics’ runs/detect/train/weights/, notably best.pt.
Inference Stage
scripts/infer.sh is the live deployment entry point. It loads the trained detector and passes the default local camera as the inference source, relying on Ultralytics for frame capture, prediction, rendering, and on-screen bounding-box display. The trained-model boundary is the generated checkpoint, typically runs/detect/train/weights/best.pt.
Runtime and External Dependencies
Python 3.8+ and packages declared in requirements.txt provide the execution environment. Core ML runtime behavior is delegated to Ultralytics YOLOv8 and PyTorch; GPU-backed PyTorch is recommended but not required by the repository interface. External data/services are the WIDER FACE dataset and its referenced CUHK-CSE Hugging Face mirror. Webcam access is required only for the live inference path.
End-to-End Control Flow
1. Install runtime dependencies from requirements.txt.
2. Run scripts/DownloadAndFormatDataset.py to materialize YOLO-compatible WIDER FACE data.
3. Run scripts/train.sh; it reads the generated dataset contract and writes experiment artifacts/checkpoints.
4. Run scripts/infer.sh or an equivalent yolo detect predict command using the trained checkpoint and a camera or image source.
The repository itself is orchestration-centric: data conversion and shell entry points define local workflow, while model training and prediction semantics remain owned by the external Ultralytics runtime.
Main entry points: DownloadAndFormatDataset.py Download and format · infer.sh Run webcam inference · requirements.txt Python dependencies · train.sh Train model
Components 14
Environment
- Python dependencies · Python 3.8+ packages, including Ultralytics and PyTorch.
requirements.txt - Ultralytics YOLOv8 · Owns training, prediction, capture, and rendering behavior.
Dataset pipeline
- WIDER FACE source · Images and annotations from the referenced mirror.
- Download and format · Downloads WIDER FACE and converts annotations to YOLO labels.
scripts/DownloadAndFormatDataset.py - Train and val images · YOLO image layout under the generated dataset root.
- Normalized YOLO labels · One normalized class-0 face bounding-box label set per image.
- Dataset contract · Defines root, image splits, and the single face class.
Training
- YOLOv8 nano base · The documented yolov8n.pt fine-tuning starting point.
- Train model · Runs the documented 50-epoch, 640px fine-tuning job.
scripts/train.sh - Detection training run · Consumes the dataset contract and produces model artifacts.
- Selected detector · Typically the best.pt model used for prediction.
Live inference
- Run webcam inference · Starts live prediction with the trained detector.
scripts/infer.sh - Local camera · Default live input source.
- Rendered detections · On-screen face bounding boxes rendered by Ultralytics.
Connections 16
- Python dependencies → Ultralytics YOLOv8: installs
- WIDER FACE source → Download and format: downloads
- Download and format → Train and val images: materializes
- Download and format → Normalized YOLO labels: converts annotations to
- Download and format → Dataset contract: writes
- Train and val images → Dataset contract: referenced as splits
- Normalized YOLO labels → Dataset contract: aligns with contract
- Train model → Ultralytics YOLOv8: invokes CLI
- Dataset contract → Detection training run: configures
- YOLOv8 nano base → Detection training run: fine-tunes
- Ultralytics YOLOv8 → Detection training run: executes
- Detection training run → Selected detector: selects
- Run webcam inference → Ultralytics YOLOv8: invokes prediction
- Selected detector → Run webcam inference: loads
- Local camera → Ultralytics YOLOv8: supplies frames
- Ultralytics YOLOv8 → Rendered detections: renders detections