How to generate an English text description of an image in Node.JS with Deep Learning

Cloudmersive
2 min readApr 2, 2020

--

Deep Learning can do more and more incredible things every day. Today we will just be focusing on using it to generate text descriptions of photos, a great way to instantly create captions for large numbers of pictures. However, we will not be starting from scratch, training up the AI from the ground up and wasting valuable time and effort. Instead, we will be doing the opposite. We will implement an API that already has access to a Deep Learning-made AI.

Let’s use npm install to set up our API client so that we can continue:

npm install cloudmersive-image-api-client --save

Now call our function with this little chunk of code here:

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveImageApiClient.RecognizeApi();var imageFile = "/path/to/file"; // 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.recognizeDescribe(imageFile, callback);

Done! Now let’s test it out on this image:

And here is our response. As you can see there are two possible choices with accompanying confidence scores, which can be used to weed our inaccurate responses.

{
"Successful": true,
"Highconfidence": true,
"BestOutcome": {
"ConfidenceScore": 0.25286288000643253,
"Description": "A group of people sitting around a table."
},
"RunnerUpOutcome": {
"ConfidenceScore": 0.07016115123406053,
"Description": "A group of people sitting at a table with laptops."
}
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet