Skip to content

yash42828/Gender-and-Age-detection-using-OpenCV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gender-and-Age-Detection

Objective :

To build a gender and age detector that can approximately guess the gender and age of the person (face) in a picture or through webcam.

About the Project :

In this Python Project, I had used Deep Learning to accurately identify the gender and age of a person from a single image of a face. I used the models trained by Adrian Rosebrock. The predicted gender may be one of ‘Male’ and ‘Female’, and the predicted age may be one of the following ranges- (0 – 2), (4 – 6), (8 – 12), (15 – 20), (25 – 32), (38 – 43), (48 – 53), (60 – 100) (8 nodes in the final softmax layer). It is very difficult to accurately guess an exact age from a single image because of factors like makeup, lighting, obstructions, and facial expressions. And so, I made this a classification problem instead of making it one of regression.

Dataset :

For this project Adience dataset is used; the dataset is available in the public domain and you can find it here. It has a total of 26,580 photos of 2,284 subjects in eight age ranges (as mentioned above) and is about 1GB in size. The models I used had been trained on this dataset.

Additional Python Libraries Required :

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

The contents of this Project :

  • opencv_face_detector.pbtxt
  • opencv_face_detector_uint8.pb
  • age_deploy.prototxt
  • age_net.caffemodel
  • gender_deploy.prototxt
  • gender_net.caffemodel
  • 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 and the .caffemodel file defines the internal states of the parameters of the layers.

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
    
  • Press Ctrl + C to stop the program execution.

Examples :

NOTE:- I downloaded the images from Google,if you have any query or problem i can remove them, i just used it for Educational purpose.

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

>python detect.py --image kid1.jpg
Gender: Male
Age: 4-6 years    

>python detect.py --image man1.jpg
Gender: Male
Age: 38-43 years

>python detect.py --image woman1.jpg
Gender: Female
Age: 38-43 years

Support :

If you found this project helpful and if you have any Query regarding this then contact me:

About

Automatically predict age and gender in static image files and real-time video streams with reasonably high accuracy.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages