Age detection of photos in Node.js

Cloudmersive
2 min readMay 27, 2019

--

Here, our goal is to determine the age of the subject in a photo using Deep Learning. Our first step is to add a reference to the needed library:

"dependencies": {
"cloudmersive-image-api-client": "^1.1.4"
}

Now, all we need to do is call the faceDetectAge method:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');
var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveImageApiClient.FaceApi();var imageFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.faceDetectAge(imageFile, callback);

Here is an example output for this image:

{
"Successful": true,
"PeopleWithAge": [
{
"FaceLocation": {
"LeftX": 855,
"TopY": 348,
"RightX": 2277,
"BottomY": 2099
},
"AgeClassificationConfidence": 0.9988910555839539,
"AgeClass": "25-32"
}
],
"PeopleIdentified": 1
}

Here we can see the AgeClass is 25–32, indicating the subject’s age is in that range. The AgeClassificationConfidence is 0.998 — a high score on the range of 0.0 to 1.0 (highest confidence).

Here is another example:

{
"Successful": true,
"PeopleWithAge": [
{
"FaceLocation": {
"LeftX": 858,
"TopY": 96,
"RightX": 1543,
"BottomY": 1015
},
"AgeClassificationConfidence": 0.7693660855293274,
"AgeClass": "25-32"
}
],
"PeopleIdentified": 1
}

That’s it! That was easy.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet