Create a gender and age detection system capable of estimating the gender and age range of an individual from a given image or webcam feed.
This Python project utilizes Deep Learning techniques to precisely identify gender and age from facial images. The model leverages training from Tal Hassner and Gil Levi. Predicted genders are categorized as 'Male' or 'Female,' while predicted age falls into specific ranges: (0 – 2), (4 – 6), (8 – 12), (15 – 20), (25 – 32), (38 – 43), (48 – 53), and (60 – 100) [with 8 nodes in the final softmax layer]. The decision to frame the problem as a classification rather than regression accounts for challenges like makeup, lighting, obstructions, and facial expressions that make exact age prediction challenging from a single image.
The Adience dataset is employed for this Python project, publicly accessible here. This dataset serves as a benchmark for face photos, encompassing diverse real-world conditions such as noise, lighting, pose, and appearance. Comprising 26,580 photos of 2,284 subjects across eight age ranges, it is distributed under the Creative Commons (CC) license and totals approximately 1GB. The models utilized in this project undergo training using this comprehensive dataset.
- OpenCV
pip install opencv-python
- argparse
pip install argparse
- opencv_face_detector.pbtxt
- opencv_face_detector_uint8.pb
- age_deploy.prototxt
- age_net.caffemodel
- gender_deploy.prototxt
- gender_net.caffemodel
- A few pictures for testing
- detect.py
- Download the repository.
- Open Command Prompt or Terminal and navigate to the folder containing all files.
- To detect gender and age in an image, use the command:
python detect.py --image <image_name>
Note: The image should be in the same folder as the files.
- To detect gender and age through the webcam, use the command:
python detect.py
- Press Ctrl + C to stop program execution.
>python detect.py --image girl1.jpg
Gender: Female
Age: 25-32 years
>python detect.py --image girl2.jpg
Gender: Female
Age: 8-12 years
>python detect.py --image kid1.jpg
Gender: Male
Age: 4-6 years
>python detect.py --image kid2.jpg
Gender: Female
Age: 4-6 years
>python detect.py --image man1.jpg
Gender: Male
Age: 38-43 years
>python detect.py --image man2.jpg
Gender: Male
Age: 25-32 years
>python detect.py --image woman1.jpg
Gender: Female
Age: 38-43 years
Connect with me on Linkedin!!