Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 3.08 KB

README.md

File metadata and controls

85 lines (63 loc) · 3.08 KB

YOLOv9 for Face Detection

The face detection task identifies and pinpoints human faces in images or videos. This repo demonstrates how to train a YOLOv9 model for highly accurate face detection on the WIDER Face dataset.

⚙️ Installation

Clone this repo and install requirements.txt for YOLOv9:

git clone https://github.com/spacewalk01/yolov9-face-detection
cd yolov9-face-detection/yolov9
pip install -r requirements.txt

🤖 Pretrained Model

Download the pretrained yolov9-c.pt model from google drive. Note that this model was trained on the WIDER dataset for 240 epochs.

📚 Data Preparation

The WIDER dataset comprises of more than 30k images with more than 390k faces, each with bouding box and other various label formats.

Dataset structure

${ROOT}
└── yolov9
└── datasets/    
    └── widerface/
        └── train/
        └── val/
    └── original-widerface/
        └── train/
            └── images/
            └── label.txt
        └── val/
            └── images/
            └── label.txt
└── train2yolo.py
└── val2yolo.py
└── widerface.yaml

To prepare the data:

  1. Download the WIDER-FACE datasets.
  2. Download the annotation files from google drive.

Run the following commands:

python train2yolo.py datasets/original-widerface/train datasets/widerface/train
python val2yolo.py datasets/original-widerface datasets/widerface/val

These scripts will convert your annotation files to YOLO format, creating one .txt file per image. Each row in the file will represent a single object in the format: class x_center y_center width height.

🏋️ Training

To train the model, use the following command:

cd yolov9
python train_dual.py --workers 4 --device 0 --batch 4 --data ../widerface.yaml --img 640 --cfg models/detect/yolov9-c.yaml --weights '' --name yolov9-c --hyp hyp.scratch-high.yaml --min-items 0 --epochs 500 --close-mosaic 15

🌱 Inference

For inference, run the following command:

python detect.py --weights runs/train/yolov9-c5/weights/best.pt --source assets/worlds-largest-selfie.jpg

Or if you want to use the trained model, download it from the above link and run the following command:

python detect.py --weights best.pt --source assets/worlds-largest-selfie.jpg

🔗 Reference

  • YOLOv9 - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
  • WIDER FACE - WIDER FACE: A Face Detection Benchmark
  • YOLO5Face - YOLO5Face: Why Reinventing a Face Detector