Age and gender prediction
In this recipe, you will learn how to predict a person's age and gender by an image. One of the possible applications is collecting statistical information about people viewing content in digital signage displays for example.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.x Python API package.
How to do it...
You need to complete the following steps:
- Import the modules:
import cv2 import numpy as np import matplotlib.pyplot as plt
- Load the models:
age_model = cv2.dnn.readNetFromCaffe('../data/age_gender/age_net_deploy.prototxt', '../data/age_gender/age_net.caffemodel') gender_model = cv2.dnn.readNetFromCaffe('../data/age_gender/gender_net_deploy.prototxt', '../data/age_gender/gender_net.caffemodel')
- Load and crop the source image:
orig_frame = cv2.imread('../data/face.jpeg') dx = (orig_frame.shape[1]-orig_frame.shape[0]) // 2 orig_frame = orig_frame[:,dx:dx+orig_frame...