Using image data, predict the gender and age range of an individual in Python

Introduction
Age and gender prediction are used extensively in the field of computer vision for surveillance. Advancement in computer vision makes this prediction even more practical and open to all. Significant improvements have been made in this research area due to its usefulness in intelligent real-world applications.

OpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture, and analysis including features like face detection and object detection. In this tutorial, we explain how you can use OpenCV in your applications.

Implementation
Typically, you’ll see age detection implemented as a two-stage process:

Stage 1: Detect faces from the input image
Stage 2: Extract the face Region of Interest (ROI), and apply the age detector algorithm to predict the age of the person

For Stage 1, any face detector capable of producing bounding boxes for faces in an image can be used
The face detector produces the bounding box coordinates of the face in the image.

For Stage 2, identifying the age of the person.
Given the bounding box (x, y)-coordinates of the face, we first extract the face ROI, ignoring the rest of the image/frame. Doing so allows the age detector to focus solely on the person’s face and not any other irrelevant “noise” in the image.

The face ROI is then passed through the model, yielding the actual age prediction.

Task: Identify and predict Gender and age-range from Photo.

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

Uploaded the image of a human and viewed the output

In this blog, We have learned how to create an Age predictor that can also detect your face and highlight it with the border.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store