GithubHelp home page GithubHelp logo

smahesh29 / gender-and-age-detection Goto Github PK

View Code? Open in Web Editor NEW
447.0 11.0 187.0 90.72 MB

A Python project which can detect gender and age using OpenCV of the person (face) in a picture or through webcam.

License: MIT License

Python 100.00%
gender-detection age-detection webcam opencv python gender age gender-prediction age-prediction opencv-python

gender-and-age-detection's Introduction

Gender-and-Age-Detection GitHub

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 Tal Hassner and Gil Levi. 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 python project, I had used the Adience dataset; the dataset is available in the public domain and you can find it here. This dataset serves as a benchmark for face photos and is inclusive of various real-world imaging conditions like noise, lighting, pose, and appearance. The images have been collected from Flickr albums and distributed under the Creative Commons (CC) license. 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
  • 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 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.

Working:

Watch the video

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

gender-and-age-detection's People

Contributors

smahesh29 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gender-and-age-detection's Issues

Version of OpenCV & Python

Which version has been used of OpenCV and Python, since I think the version is why I am getting an error:
cv2.error: OpenCV(4.7.0) /Users/xperience/GHA-OCV-Python/_work/opencv-python/opencv-python/opencv/modules/dnn/src/caffe/caffe_io.cpp:1138: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "opencv_face_detector_uint8.pb" in function 'ReadProtoFromBinaryFile'

Train the model

Hi,first of all thank you for making this amazing project.i want to ask how can i train the model again?do you have a ipynb file for that or a python file?

Control C to stop execution

Hi Mahesh,

Why do we need to use "Control C" to stop the execution? I am trying to use the code in a loop to process multiple photos. Is there any way to stop it so it can work in a loop?

Thanks,
Jing

How to upload caffemodel to github?

Hi, I want to deploy the gender and age detection project to cloud. I'm not able to upload caffemodels to github. Could you suggest how have you done?

install in python3

pip3 install opencv-python
pip3 install argparse
apt-get install -y libqtgui4
sudo apt install libqt4-test
pip3 install opencv-contrib-python
install opencv-contrib-python==4.1.0.25

New version of gender_net.caffemodel and age_net.caffemodel

Dear Mahesh Sawant,

We are working on age and gender recognition algorithms. The version of Caffe models which you used is an old version. While we are upgrading the version by tools, there are some errors. Please, can you share the new version of the Caffe model?

Understandig how the face detection works

Hi, the age and gender detection works good, thanks for sharing!
I want to understand how the face detection works.
Can you tell me if you use Single Shot detector or something else?

Code gets stuck in the infinite loop

Hi Mahesh,

While running the code in windows terminal the window detects the age in real time but when trying to close the window it doesn't gets closed so need to close the terminal itself to abort it.

Thanks,
Ansh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.