Skip to content

A Python project which can detect gender and age using OpenCV of the person in a image or through camera.

License

Notifications You must be signed in to change notification settings

charan12-git/Gender-and-Age-Detection

Repository files navigation

Gender-and-Age-Detection

Objective

Develop a gender and age detection system capable of estimating the gender and age range of a person based on their facial image, either from a photo or a webcam feed.

This Python-based project leverages deep learning techniques to estimate gender and age from a single facial image. The models, pre-trained by Tal Hassner and Gil Levi, have been utilized to perform these predictions. The gender prediction outputs one of two categories: Male or Female. For age, the system predicts one of the following predefined ranges:

(0 – 2) (4 – 6) (8 – 12) (15 – 20) (25 – 32) (38 – 43) (48 – 53) (60 – 100) The classification approach was chosen over regression due to the inherent challenges in pinpointing an exact age from a single image. Factors such as makeup, lighting, obstructions, and facial expressions can significantly impact accuracy. By framing it as a classification problem, the model can effectively assign the image to the most probable age range.

Additional Python Libraries Required :

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

Contents :

  • opencv_face_detector.pbtxt
  • opencv_face_detector_uint8.pb
  • age_deploy.prototxt
  • gender_deploy.prototxt
  • a few pictures to try the project on
  • detect.py

For face detection, we have a .pb file- this is a protobuf file (protocol buffer); it holds the graph definition and the trained weights of the model. We can use this to run the trained model. And while a .pb file holds the protobuf in binary format, one with the .pbtxt extension holds it in text format. These are TensorFlow files. For age and gender, the .prototxt files describe the network configuration

Usage :

  • Download my Repository
  • Open your Command Prompt or Terminal and change directory to the folder where all the files are present.
  • Detecting Gender and Age of face in Image Use Command :
  •   python detect.py --image <image_name>
    

Note: The Image should be present in same folder where all the files are present

  • Detecting Gender and Age of face through webcam Use Command :
  •   python detect.py
    

Working And Examples

>python detect.py --image woman_1.jpg
Gender: Female
Age: 25-32years 

>python detect.py --image oldman_2.jpg
Gender: Male
Age: 60-100 years

>

  • python detect.py --image man_1.jpg
  • Gender: Man
  • Age: 25-32 years
  • >python detect.py --image girl_2.jpg
    Gender: Female
    Age: 8-12 years  
    

    About

    A Python project which can detect gender and age using OpenCV of the person in a image or through camera.

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages