Toan Le
commited on
Commit
·
24c61d2
1
Parent(s):
f0e8296
Adjust relative paths; Add metrics; Write README
Browse files
README.md
CHANGED
@@ -1,13 +1,151 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Age Gender Detector
|
2 |
+
|
3 |
+
This project implements a semi-real-time age and gender detection application using a combination of pre-trained YOLOv8
|
4 |
+
and fine-tuned YOLOv11 models from [Ultralytics](https://www.ultralytics.com/). The application processes either a
|
5 |
+
single image or a live video feed from a webcam, detects faces, and then predicts the age and gender of each detected
|
6 |
+
individual.
|
7 |
+
|
8 |
+
The application is built with Python 3.10.3 and Gradio, providing a user-friendly web interface.
|
9 |
+
|
10 |
+
A demo can be found [here](https://nguyentoanle41-age-gender-detector.hf.space/).
|
11 |
+
|
12 |
+
## Contents
|
13 |
+
1. [Features](#1-features)
|
14 |
+
2. [Setup](#2-setup)
|
15 |
+
3. [How to Run](#3-how-to-run)
|
16 |
+
4. [Model Training and Datasets](#4-model-training-and-datasets)
|
17 |
+
5. [Performance Results](#5-performance-results)
|
18 |
+
|
19 |
+
## 🚀 Getting Started
|
20 |
+
|
21 |
+
## 1. Features
|
22 |
+
- **Face Detection**: Utilizes a YOLOv8-based face detection model to accurately locate faces in images and video frames.
|
23 |
+
- **Age and Gender Classification**: Employs two separate YOLOv11 classification models, fine-tuned for age and gender
|
24 |
+
prediction.
|
25 |
+
- **Real-time Processing**: Supports real-time video processing from a webcam, with bounding boxes and predictions
|
26 |
+
displayed directly on the video feed.
|
27 |
+
- **User-friendly Interface**: A simple and intuitive web interface is provided by Gradio, allowing users to easily
|
28 |
+
upload images or use their camera for live feeding. A demo can be found
|
29 |
+
[here](https://nguyentoanle41-age-gender-detector.hf.space/).
|
30 |
+
|
31 |
+
## 2. Setup
|
32 |
+
### Prerequisites
|
33 |
+
- Python 3.8 or higher.
|
34 |
+
- `pip` package manager.
|
35 |
+
|
36 |
+
### Installation
|
37 |
+
1. Clone the repository:
|
38 |
+
```
|
39 |
+
git clone https://github.com/NguyenToanLe/Age-Gender-Detection-YOLO.git
|
40 |
+
cd Age-Gender-Detection-YOLO
|
41 |
+
```
|
42 |
+
|
43 |
+
2. Install the required Python packages
|
44 |
+
```
|
45 |
+
pip install -r requirements.txt
|
46 |
+
```
|
47 |
+
|
48 |
+
## 3. How to Run
|
49 |
+
|
50 |
+
If you don't want to use web interface, you can directly run `predictor.py` script. This will make the detection via
|
51 |
+
live camera usage smoother.
|
52 |
+
```python
|
53 |
+
python predictor.py
|
54 |
+
```
|
55 |
+
|
56 |
+
To start the application via web interface locally, simply run the `app.py` script from your terminal. Either use on of
|
57 |
+
these two commands:
|
58 |
+
```python
|
59 |
+
python app.py
|
60 |
+
gradio app.py
|
61 |
+
```
|
62 |
+
This will launch a Gradio server. You can access the application by navigating to the local URL provided in the terminal
|
63 |
+
output (e.g., `http://127.0.0.1:7860`). With the second command, the web-app will be automatically updated when you make
|
64 |
+
change in `app.py` script.
|
65 |
+
|
66 |
+
## 4. Model Training and Datasets
|
67 |
+
|
68 |
+
The age and gender classification models were fine-tuned separately. The notebooks used for training are available in
|
69 |
+
the `notebooks/` directory.
|
70 |
+
|
71 |
+
### Datasets
|
72 |
+
#### Age Classification
|
73 |
+
The model for age prediction was fine-tuned on
|
74 |
+
[Age-Classification-Set](https://huggingface.co/datasets/prithivMLmods/Age-Classification-Set) dataset, which consists
|
75 |
+
of images of faces with corresponding age range labels. There are five age groups: `0-12, 13-20, 21-44, 45-64, 65+`.
|
76 |
+
|
77 |
+
There are `19016` images, with the distribution as following:
|
78 |
+
|
79 |
+
- `0-12`: 2193 samples
|
80 |
+
- `13-20`: 1779 samples
|
81 |
+
- `21-44`: 9999 samples
|
82 |
+
- `45-64`: 3785 samples
|
83 |
+
- `65+`: 1260 samples
|
84 |
+
|
85 |
+
Because the number of `21-44` group is exceeded, the number of these images is randomly reduced to `4000` samples
|
86 |
+
(comparable to the second most class in the dataset, `45-64`).
|
87 |
+
|
88 |
+
Then these images were split with the ratios `train : eval : test = 8 : 1 : 1` evenly to ensure a balanced distribution
|
89 |
+
across different age groups, which is crucial for achieving high accuracy.
|
90 |
+
|
91 |
+
#### Gender Classification
|
92 |
+
The model for gender prediction was fined-tuned on
|
93 |
+
[gender-classification](https://huggingface.co/datasets/myvision/gender-classification) dataset, which consists of
|
94 |
+
images of faces with corresponding gender, either `female` or `male`.
|
95 |
+
|
96 |
+
This dataset was already split into `train, eval, test` sets with the number of images in each set as following:
|
97 |
+
|
98 |
+
- `train`: 5000 samples
|
99 |
+
- `eval`: 1000 samples
|
100 |
+
- `test`: 1000 samples
|
101 |
+
|
102 |
+
## 5. Performance Results
|
103 |
+
|
104 |
+
#### Age Classification Report
|
105 |
+
|
106 |
+
This classifier was trained with `50` epochs and images were reduced to the size of `64`. This model reaches the overall
|
107 |
+
accuracy of `79.14%`. The detailed performance is given by the table and confusion matrix below.
|
108 |
+
|
109 |
+
<div style="margin-left: auto;
|
110 |
+
margin-right: auto;
|
111 |
+
width: 50%">
|
112 |
+
|
113 |
+
| Age Groups | Precision | Recall | F1-score |
|
114 |
+
|------------|----------:|-------:|---------:|
|
115 |
+
| 0-12 | 0.89 | 0.95 | 0.92 |
|
116 |
+
| 13-20 | 0.69 | 0.61 | 0.65 |
|
117 |
+
| 21-44 | 0.77 | 0.75 | 0.76 |
|
118 |
+
| 45-64 | 0.79 | 0.82 | 0.80 |
|
119 |
+
| 65+ | 0.78 | 0.83 | 0.80 |
|
120 |
+
</div>
|
121 |
+
|
122 |
+
<div style="text-align: center;">
|
123 |
+
|
124 |
+

|
125 |
+
</div>
|
126 |
+
|
127 |
+
The metrics show that the model still confuse between two adjacent groups, except for the youngest group. This can be
|
128 |
+
improve through hyperparameter tuning or through the enhancement of the dataset.
|
129 |
+
|
130 |
+
#### Gender Classification Report
|
131 |
+
|
132 |
+
This classifier was trained with `10` epochs and images were reduced to the size of `64`. This model reaches the overall
|
133 |
+
accuracy of `92.50%`. The detailed performance is given by the table and confusion matrix below.
|
134 |
+
|
135 |
+
<div style="margin-left: auto;
|
136 |
+
margin-right: auto;
|
137 |
+
width: 50%">
|
138 |
+
|
139 |
+
| Gender | Precision | Recall | F1-score |
|
140 |
+
|--------|----------:|-------:|---------:|
|
141 |
+
| female | 0.94 | 0.91 | 0.92 |
|
142 |
+
| male | 0.91 | 0.94 | 0.93 |
|
143 |
+
</div>
|
144 |
+
|
145 |
+
<div style="text-align: center;">
|
146 |
+
|
147 |
+

|
148 |
+
</div>
|
149 |
+
|
150 |
+
The classifier can improve in performance through hyperparameter tuning (e.g., increasing epochs because the training
|
151 |
+
process did not reach the overfitting point).
|