Data Science: Predict the Gender and Age Range of an Individual in Python

Dhrumil Dalwadi
2 min readOct 28, 2021

Age and Gender have always been important features of our identity. It is also an important factor in our social life. Predictions of age and Gender made with AI can be applied to many areas such as intelligent human-machine interface development, security, cosmetics, electronic commerce.

OpenCV is short for Open Source Computer Vision. Intuitively by the name, it is an open-source Computer Vision and Machine Learning library. This library is capable of processing real-time images and videos while also boasting analytical capabilities.

We will use OpenCV to accurately identify the gender and age of a person from a single image of a face. 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).

The steps we must take are as follows.

Step 1: Importing libraries

Step 2: Finding bounding box coordinates

Step 3: Loading model and weight files

Step 4: Mentioning age and gender category list

Step 5: Function to predict gender and age

Step 6: Uploading photo

Final result:

You can find the code below

--

--