Age detection is one of the many useful tools that have been developed as a result of Deep Learning technology; these algorithms are an excellent method to gather demographic information to use in marketing campaigns. However, training an AI with Deep Learning can be a complex and cumbersome task — to evade this process, we will be demonstrating how you can use an API in Python to identify the age, position, and size of human faces in an image.
First, run this command to install the API client:
pip install cloudmersive-image-api-client
Next, you can call the function with the following code:
from __future__ import print_function
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'# create an instance of the API class
api_instance = cloudmersive_image_api_client.FaceApi(cloudmersive_image_api_client.ApiClient(configuration))
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try:
# 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)
This simple operation will return the information previously mentioned, as well as an age confidence score to let you know how accurate the age identification is.