We had the task of sorting people's profiles by age and gender . We needed to segment the base of potential clients to launch test advertising campaigns ; for each advertising campaign, we selected individual videos that would best suit people of a certain age and gender.
If you are interested in such topics and want to continue to see new publications and development of this module, then we ask you to give us a star ⭐ on Github!
Module link : https://github.com/mowshon/age-and-gender
After analyzing the available libraries, we found an interesting repository on Github: https://github.com/davisking/dlib-models
The author Davis E. King @davisking, who is also the creator of the wonderful dlib library, has provided an already trained model for several thousand people’s faces. But here’s the problem... the code is written in C++ and we haven’t found a working alternative in Python.
Age prediction model (dnn_age_predictor_v1.dat)
The original source for creating the model came from Z. Qawaqneh's paper: " Deep Convolutional Neural Network for Age Estimation Based on VGG-Face Model ". However, our research has led us to significant improvements in the CNN model, allowing us to estimate a person's age superior to existing results in terms of result accuracy.
Have questions about Python?
On our forum you can ask any question and get an answer from our entire community!
Python Help Forum
Telegram Chat & Channel
Join our friendly Python chat and start communicating with like-minded people! Become part of a big community!
Chat
Channel
Public VK
One of the largest Python communities on the VK social network. Video lessons and books for you!
Subscribe
Thus, this model is an age detector using the ResNet-10 , and is trained using a private dataset of approximately 110 thousand different images of people annotated with their age.
age prediction model is provided free of charge by Cydral Technology and licensed under a Creative Commons Zero v1.0 Universal license.
Download link: https://github.com/davisking/dlib-models/blob/master/age-predictor/dnn_age_predictor_v1.dat.bz2
Service How Old
This site is developed by Microsoft. It uses machine algorithms to determine a person's age from an online photo. The scan is carried out according to the shape of the face, the shape of the nose, mouth, position of the eyes, eyebrows and ears is analyzed. At the same time, the developers emphasize that the service does not allow you to accurately find out the necessary parameters. It is made with the purpose of entertaining users.
The service is presented not only as a web version, but also as a mobile application. When used for the first time, so that the user can be convinced that the program is working, templates of photographs of people will be presented that can be scanned. The following are step-by-step instructions on how to use the web version of How Old, because... mobile is used only on iOS and is linked to American iTunes.
Instructions:
- go to the how old website;
- then on the main page click on the “ Use Your Own Photo ” tab;
- An explorer window will open where you need to select the desired photo;
- after this, the process of analyzing the object will begin and the result will be shown in a pop-up window. We took as an example a photo of 23-year-old model Jelena Hadid, and the result turned out to be 29 years old. Having tested the operation of the resource, in our case, the program showed not entirely accurate data, the error was +-3-7 years.
How to delete your page or the entire Telegram application
You can also see the photo instructions below:
Model for determining a person's gender by face (dnn_gender_classifier_v1.dat)
This model is a gender classifier trained using a private dataset of approximately 200,000 different face images , and it was generated according to the network definition and settings specified in “A Minimalistic CNN-Based Model for Predicting Gender from Face Images.” Even if the dataset used for training is different from the one used by G. Antipov, the classification results according to the LFW assessment are generally similar (± 97.3%).
This gender model is provided free of charge by Cydral Technology and licensed under a Creative Commons Zero v1.0 Universal license.
Download link: https://github.com/davisking/dlib-models/blob/master/gender-classifier/dnn_gender_classifier_v1.dat.bz2
Age recognition from photographs
— www.log-in.ru
Researchers in the United States report that a new computer program has been created to recognize a person's age by analyzing faces in photographs. She is able to estimate a person's age by the way he looks.
Special software was developed by a team from the University of Illinois.
“Measuring age is a very complex procedure,” says Dr. Thomas Huang, the project leader. “If we use the face as an indicator of age, we can actually determine true age, or the age that a person appears to be.”
The researchers trained their computer with a special algorithm using images of 1,600 people, 5 photos of each. In total, 8,000 photos were used. The age of the people in the photographs ranged from one year to 93 years.
Huang didn't tell the computer what to look for. The computer examined the faces and used its software to determine those features that best reflected the person's true age.
Grayscale Analysis
One of the features that the computer looked at was the gray scale. If, for example, you analyze a photograph measuring 100x100 pixels, then each of the 10,000 pixels has its own shade of gray.
By comparing how much a given point is lighter or darker compared to others, the program calculates the individual's real age.
“A woman who wears makeup will appear younger,” Huang says. “Smoother skin texture will be recognized as more youthful.”
The computer also looks at your face shape. The relative position of the eyes, nose, ears, and mouth shape all change over time and can help determine age.
"If you take a person's actual age as truth, then the accuracy is quite low," says Huang. “But if you limit the age to ten years, the accuracy is about 80%.”
Shape, position, color and texture help in determining not only age, but also ethnicity, gender, and even emotions. Huang studies all this using a computer.
“We are more accurate in gender recognition, about 90%,” says Huang. “Also, the result was 90% when recognizing positive emotions, such as a smile. Negative emotions, such as surprise, are not so easy to define.”
Computer age recognition from photographs is not just an academic experiment in computer science. Several companies are actually interested in using this software.
Without going into detail, Huang says facial recognition software could be useful for, say, fast food companies that want to know how many young people are buying a certain type of sandwich; or for clothing companies that could show different ads to everyone who enters their store.
“If you can determine the gender and age of the buyer, then you can change the advertising on the display,” says Huang. “It may be better to show one commercial for young people and another for mature people.”
Variable biometrics
“Facial recognition software could also be useful for security purposes,” says Dr. Jonathan Phillips, a fellow at the National Institute of Standards and Technology, which develops the software.
Variable biometrics such as age or gender (as opposed to fixed biometrics such as fingerprints or palm vein patterns) could be used as a secondary security metric to a PIN for identification at ATMs or at building entrances.
Whatever this program is used for, expect to see it in action within a few years. The system can be built into security cameras to capture images and then process them using appropriate software.
Huang and Phillips try to make sure that there is no need for additional equipment such as cameras or special lighting.
The only difficulty with Huang's program is that it works best when the face is facing the camera. Side-on photos make it more difficult to discern age, gender, ethnicity, or emotion. Huang is working on improving the software to be able to read people's faces from different angles.
The main test for age recognition programs is how well they can recognize age compared to humans.
Huang believes his software can match the age-determining accuracy of the human eye. Phillips says people are very good at guessing the ages of their friends and loved ones, but have difficulty guessing the ages of strangers.
"We do this all the time," Phillips says. “When people invent something new, they want it to be useful. If a computer is more accurate than a human in determining age, emotions, etc., then this will make communication between computers and people more positive.”
Translation: Nikonov Vladimir
The article was prepared by:
Vladimir Nikonov, Dmitry Trost
Articles about nature, inventions, architecture, illusions...
Porting C++ Code to Python
Initially, @davisking provided two C++ files that showed how to work with the models he trained:
- dnn_gender_classifier_v1_ex.cpp
- dnn_age_predictor_v1_ex.cpp
They output the result directly to the console, but using the code in a working project, even in C++, was extremely inconvenient. Using pybind11 we are able to apply C++ code to our Python code. We won't focus on pybind11 , but if you want to get acquainted with it, we recommend the article: Creating C++ Python extensions using pybind11
How to determine age without services
All of the above resources work with the following parameters, with the help of which the final result is formed:
- wrinkles _ At 20 years old, skin unevenness is not as noticeable as at 30 years old. At 50 years old, wrinkles are much more pronounced. The program takes into account these features and generates the final result;
- The scanning algorithms are mainly based on gray tone analysis . Let’s say that if the original photo size is no more than 100 pixels, then each of the 10,000 will have its own shade, from the lightest to the darkest. The program begins to compare several pixels darker and lighter from each other and determines the age parameters;
- The size of the face, the position of the nose and eyes, and the shape of the mouth and ears are also compared The software takes into account these features, since they change significantly throughout a person’s life;
- If a woman uses a lot of cosmetics, then it is difficult to find out the number of years using the software method, since the skin texture will have a small number of flaws.
Services and programs for quickly translating text from an image or photograph
Using the information indicated above, you can try to find out the number of years yourself from the photo. This is quite difficult, but quite possible.
Installing age-and-gender on Ubuntu & Debian
We recommend doing any new projects and testing modules in a virtual environment, this way you will not clog up your system interpreter with unnecessary modules. First of all, we create a virtual environment and activate it.
Shell
1 2 | python3 -m venv venv source venv/bin/activate |
Install the necessary dependencies:
Shell
1 | sudo apt install cmake libjpeg-dev g++ build-essential libfreetype6-dev |
Download the files from github and perform the installation:
Shell
1 2 3 | git clone [email protected]:mowshon/age-and-gender.git cd age-and-gender python setup.py install |
In the example there is a test file example.py, when you run it you will see how the script determined the ages of Bill Gates' family members.
Python
1 2 | cd example/ python example.py |