This project combines YOLOv8 (You Only Look Once v8) for real-time object detection with deep learning models for Age and Gender classification. It uses a webcam to detect people and estimate their age and gender, while also detecting other objects trained on the COCO dataset.
- Real-time object detection using YOLOv8 (
yolov8n.pt
). - Detects persons and applies age & gender prediction.
- Uses OpenCV DNN models (
.prototxt
+.caffemodel
) for classification. - Displays bounding boxes, confidence scores, and age/gender labels.
Install the following dependencies before running:
pip install ultralytics opencv-python torch numpy
Download and place the following files in your project directory:
yolov8n.pt
→ Ultralytics YOLOv8deploy.prototxt
→ Face detection prototxtage_deploy.prototxt
andage_net.caffemodel
→ Age classification modelgender_deploy.prototxt
andgender_net.caffemodel
→ Gender classification model
(Age & gender models are usually available from OpenCV’s sample DNN models repository.)
-
Clone this project or copy the script.
-
Ensure all
.prototxt
and.caffemodel
files are in the same directory. -
Run the script:
python age_gender_yolo.py
-
A webcam window will open showing detections.
-
Press
q
to exit.
- YOLOv8 → COCO dataset (80 classes, including
person
) - Gender →
Male
,Female
- Age →
(0-2), (4-6), (8-12), (15-20), (25-32), (38-43), (48-53), (60-100)
- YOLOv8 detects all objects, but age & gender estimation is only applied when a person is detected.
- You can replace
yolov8n.pt
withyolov8s.pt
for better accuracy (but slightly slower performance). - Ensure good lighting for more accurate predictions.
- Improve accuracy using deep learning-based face detectors instead of Caffe models.
- Train custom age/gender datasets for more precise classification.
- Extend project to detect mood/emotions along with age and gender.