Age detection of photos in Python

Let’s keep this very simple. First, pip install the API client.

pip install git+

Next, call face_detect_age and provide it with an input image.

from __future__ import print_function
import time
import cloudmersive_image_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'
# create an instance of the API class
api_instance = cloudmersive_image_api_client.FaceApi(cloudmersive_image_api_client.ApiClient(configuration))
image_file = '/path/to/file' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
# Detect the age of people in an image
api_response = api_instance.face_detect_age(image_file)
except ApiException as e:
print("Exception when calling FaceApi->face_detect_age: %s\n" % e)

Pretty easy, huh? Let’s look at an example:

Image for post
Image for post

Our return:

"Successful": true,
"PeopleWithAge": [
"FaceLocation": {
"LeftX": 200,
"TopY": 107,
"RightX": 403,
"BottomY": 335
"AgeClassificationConfidence": 0.9,
"AgeClass": "25-32",
"Age": 25.75040626525879
"PeopleIdentified": 1

You will notice that the function supports multiple people, provides their location within the photo, age range, a best guess at their exact age, and confidence rating of the assessment.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

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