Git Product home page Git Product logo

mowshon / age-and-gender Goto Github PK

View Code? Open in Web Editor NEW
95.0 11.0 19.0 28.38 MB

Predict Age and Gender of people from images | Determination of gender and age

Home Page: https://python-scripts.com

License: MIT License

CMake 0.90% Python 2.35% C++ 95.43% C 0.21% Cuda 0.43% Shell 0.10% Java 0.04% MATLAB 0.01% Batchfile 0.01% Makefile 0.03% CSS 0.04% JavaScript 0.01% HTML 0.09% XSLT 0.36% Perl 0.01% Objective-C 0.01%
faces face-images dataset face-recognition gender-classification gender-recognition gender-detection age-detection age-estimation

age-and-gender's Introduction

Predict Age and Gender using Python

This module will help you determine the gender and age of people from the image. The predict method returns a list of faces of people who were found in the image with a possible age and gender of the person.

Available for Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8

img

© Bill Gates family

Instalation

git clone [email protected]:mowshon/age-and-gender.git
cd age-and-gender
python3 setup.py install --user

Download the pre-trained models

We use already trained models. Thanks for the provided models from: https://github.com/davisking/dlib-models

Author: Davis E. King

  1. shape_predictor_5_face_landmarks.dat.bz2 Download

This is a 5 point landmarking model which identifies the corners of the eyes and bottom of the nose. It is trained on the dlib 5-point face landmark dataset, which consists of 7198 faces. @davisking created this dataset by downloading images from the internet and annotating them with dlib's imglab tool.

  1. dnn_age_predictor_v1.dat.bz2 Download

The initial source for the model's creation came from the document of Z. Qawaqneh et al.: "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 the age of a person outperforming the state-of-the-art results in terms of the exact accuracy and for 1-off accuracy.

This model is thus an age predictor leveraging a ResNet-10 architecture and trained using a private dataset of about 110k different labelled images. During the training, we used an optimization and data augmentation pipeline and considered several sizes for the entry image.

This age predictor model is provided for free by Cydral Technology and is licensed under the Creative Commons Zero v1.0 Universal.

  1. dnn_gender_classifier_v1.dat.bz2 Download

This model is a gender classifier trained using a private dataset of about 200k different face images and was generated according to the network definition and settings given in Minimalistic CNN-based ensemble model for gender prediction from face images. Even if the dataset used for the training is different from that used by G. Antipov et al, the classification results on the LFW evaluation are similar overall (± 97.3%). To take up the authors' proposal to join the results of three networks, a simplification was made by finally presenting RGB images, thus simulating three "grayscale" networks via the three image planes. Better results could be probably obtained with a more complex and deeper network, but the performance of the classification is nevertheless surprising compared to the simplicity of the network used and thus its very small size.

This gender model is provided for free by Cydral Technology and is licensed under the Creative Commons Zero v1.0 Universal.

  1. Unpack the *.bz2 archives, you need only the .dat file.

Folder structure

test_example
-- shape_predictor_5_face_landmarks.dat
-- dnn_age_predictor_v1.dat
-- dnn_gender_classifier_v1.dat
-- test-image.jpg
-- example.py

Example

from age_and_gender import AgeAndGender
from PIL import Image

data.load_shape_predictor('shape_predictor_5_face_landmarks.dat')
data.load_dnn_gender_classifier('dnn_gender_classifier_v1.dat')
data.load_dnn_age_predictor('dnn_age_predictor_v1.dat')

image = Image.open('test-image.jpg').convert("RGB")
result = data.predict(image)

print(result)

Result:

[{'age': {'confidence': 85, 'value': 26},
  'face': [414, 265, 504, 355],
  'gender': {'confidence': 100, 'value': 'female'}},
 {'age': {'confidence': 58, 'value': 62},
  'face': [223, 199, 330, 307],
  'gender': {'confidence': 99, 'value': 'female'}},
 {'age': {'confidence': 73, 'value': 19},
  'face': [593, 128, 700, 235],
  'gender': {'confidence': 99, 'value': 'male'}},
 {'age': {'confidence': 50, 'value': 24},
  'face': [342, 534, 450, 641],
  'gender': {'confidence': 100, 'value': 'female'}},
 {'age': {'confidence': 92, 'value': 61},
  'face': [782, 116, 872, 206],
  'gender': {'confidence': 99, 'value': 'male'}}]

Examples of determining the gender and age of people from the image

Code: https://github.com/mowshon/age-and-gender/tree/master/example

How to increase efficiency with face_recognition ?

The module will try to determine where the faces of people are on the image. But, it is better for us to provide a variable with people's faces using the library face_recognition and method face_locations().

python -m pip install numpy --user
python -m pip install face_recognition --user

Code:

from age_and_gender import *
from PIL import Image
import face_recognition
import numpy


data = AgeAndGender()
data.load_shape_predictor('models/shape_predictor_5_face_landmarks.dat')
data.load_dnn_gender_classifier('models/dnn_gender_classifier_v1.dat')
data.load_dnn_age_predictor('models/dnn_age_predictor_v1.dat')

filename = 'test-image-2.jpg'

img = Image.open(filename).convert("RGB")
face_bounding_boxes = face_recognition.face_locations(
    numpy.asarray(img),  # Convert to numpy array
    model='hog'  # 'hog' for CPU | 'cnn' for GPU (NVIDIA with CUDA)
)

result = data.predict(img, face_bounding_boxes)

Module age-and-gender without face_recognition

img

Module age-and-gender with face_recognition and face_bounding_boxes

img

Full example of code: https://github.com/mowshon/age-and-gender/blob/master/example/example-with-face-recognition.py

Changelog

Version 1.0.1

  • The method predict(pillow_img) now require a PIL.Image object. Thanks to @arrufat for the piece of code that successfully performs the matrix conversion.
  • The method predict(pillow_img, face_bounding_boxes) takes another argument face_bounding_boxes with a list of faces in the image. Check out this example.
  • If the method predict(pillow_img) does not get the second argument face_bounding_boxes with a list of faces, then the module will try to find the faces in the image itself.

Version 1.0.0

  • Initial commit and code

age-and-gender's People

Contributors

mowshon 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

age-and-gender's Issues

Problems with installation. returned non-zero exit status 1.

Hi. Could you help me?

PS C:\Users\User\Downloads\age-and-gender-master> python setup.py install --user
running install
running bdist_egg
running egg_info
creating age_and_gender.egg-info
writing age_and_gender.egg-info\PKG-INFO
writing dependency_links to age_and_gender.egg-info\dependency_links.txt
writing requirements to age_and_gender.egg-info\requires.txt
writing top-level names to age_and_gender.egg-info\top_level.txt
writing manifest file 'age_and_gender.egg-info\SOURCES.txt'
reading manifest file 'age_and_gender.egg-info\SOURCES.txt'
writing manifest file 'age_and_gender.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:7 (PROJECT):
Generator

NMake Makefiles

does not support platform specification, but platform

x64

was specified.

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Downloads/age-and-gender-master/build/temp.win-amd64-3.8/Release/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "setup.py", line 67, in
setup(
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools_init_.py", line 165, in setup
return distutils.core.setup(**attrs)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\command\install.py", line 67, in run
self.do_egg_install()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install
self.run_command('bdist_egg')
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\command\bdist_egg.py", line 174, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\command\bdist_egg.py", line 160, in call_command
self.run_command(cmdname)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\setuptools\command\install_lib.py", line 11, in run
self.build()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\command\install_lib.py", line 107, in build
self.run_command('build_ext')
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "setup.py", line 32, in run
self.build_extension(ext)
File "setup.py", line 60, in build_extension
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', 'C:\Users\User\Downloads\age-and-gender-master', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\User\Downloads\age-and-gender-master\build\lib.win-amd64-3.8\', '-DPYTHON_EXECUTABLE=C:\Users\User\AppData\Local\Programs\Python\Python38\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\User\Downloads\age-and-gender-master\build\lib.win-amd64-3.8\', '-A', 'x64']' returned non-zero exit status 1.

cpu

will it work with cpu only?

CalledProcessError

Hello! Help please, I cannot understand what needs to be fixed to solve this error at the installation stage...

running install
running bdist_egg
running egg_info
writing age_and_gender.egg-info\PKG-INFO
writing dependency_links to age_and_gender.egg-info\dependency_links.txt
writing requirements to age_and_gender.egg-info\requires.txt
writing top-level names to age_and_gender.egg-info\top_level.txt
reading manifest file 'age_and_gender.egg-info\SOURCES.txt'
writing manifest file 'age_and_gender.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
C:\Users\username\Documents\FILES\Packages\age_gender\age-and-gender
-- Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.18363.
-- pybind11 v2.5.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/username/Documents/FILES/Packages/age_gender/age-and-gender/build/temp.win-amd64-3.6/Release
Microsoft (R) Build Engine версии 15.8.169+g1ccb72aefa для .NET Framework
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

source.cpp
c:\users\username\documents\files\packages\age_gender\age-and-gender\libs\dlib\dlib\all../image_loader/png_loader.c
pp(13): fatal error C1083: Не удается открыть файл включение: png.h: No such file or directory, [C:\Users\username\D
ocuments\FILES\Packages\age_gender\age-and-gender\build\temp.win-amd64-3.6\Release\age_and_gender.vcxproj]
Traceback (most recent call last):
File "setup.py", line 63, in build_extension
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)#, shell=True
File "C:\Anaconda3\lib\subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '/m']' returned non-zero exit status 1.

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.