/Gender_Detection_and_Age_Prediction

A Python project that involves using OpenCV to detect the gender and age of a person in a picture or through a webcam. The goal is to analyze the face and provide information about the gender and age of the individual.

Primary LanguagePythonMIT LicenseMIT

Gender Detection & Age Prediction

Objective :

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.

Project Description:

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.

Dataset :

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.

Required Python Libraries:

  • OpenCV
  •   pip install opencv-python
    
  • argparse
  •   pip install argparse
    

Project Contents:

  • 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
For face detection, the .pb file is a protobuf file holding the graph definition and trained model weights in binary format. The .pbtxt extension signifies the same content in text format, specifically for TensorFlow. Regarding age and gender, the .prototxt files detail network configuration, while the .caffemodel file specifies internal states of layer parameters.

Usage :

  • 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.

Examples :

>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

Thank You!

Connect with me on Linkedin!!

Akshat Singh Linkedin