Machine Learning is an idea to learn from examples and experience, without being explicitly programmed. Instead of writing code, you feed data to the generic algorithm, and it builds logic based on the datasets given.

Artificial Intelligence by Techaorha Solutions Private LImited
Artificial Intelligence

In this article, we are going to cover a simple example of Machine Learning by integrating “Google Video-Intelligence” API with Node.js application.

 

What is Google Video-Intelligence?

Google under the project of Machine Learning has introduced Video-Intelligence. This makes video searchable and discoverable by extracting contents of a video with an easy to use REST API. furthermore, you can read more about google video intelligence on the google page.

 

Prerequisites for Machine Learning

  • Basic knowledge of Node.js applications
  • Basic knowledge of Google Cloud Platform

Step 1: Enable the Google Video-Intelligence API

  1. Sign into your google account with valid user credentials
  2. In the Google Cloud Platform Console, go to the Manage resources page and select or create a new project.
  3. Make sure that billing is enabled for your project. Also, you can find guidelines on the google docs link.
  4. Enable the Cloud Video Intelligence API.

Step 2: Authenticating to a Cloud API Service

To allow your application code to use a Cloud API, you will need to set up the proper credentials for your application to authenticate its identity to the service and to obtain authorization to perform tasks. The simplest authentication scheme is that of an API key.

However, an API key does not allow you to authorize to the service, so it is only usable on public data or data you pass directly to the RPC API.

 

Set up an API key

After you enable a Cloud API, Go to “API & Services” through navigation menu.

Click “Go to Credentials” to click on the Create Credentials button. Select “API key” from the options. You may wish to copy your key and keep it secure (you can also retrieve it from the API Manager→Credentials page).

 

Set up a service account for machine learning

Google Cloud Platform API authentication and authorization (commonly grouped together as “auth”) is typically done using a service account. in addition, A service account allows your code to send application credentials directly to the Cloud API.

Go to “API & Services” through navigation menu. Click on “Create Credentials” and select “Service account key”.

Select service account as “Compute engine default service account”, select key type as JSON and hit the Create button. Finally, GCP Console will generate a JSON key (as a .json text file), prompt you to download the file to your computer.

The generated JSON key will be similar to the following sample JSON key:

Install and initialize the Cloud SDK

Download appropriate google cloud SDK to your OS platform. The installer starts a terminal window and runs the gcloud init command in windows (for other operating systems, manually run the same command). Go through the online guide for detailed information.

Provide authentication credentials to your application code by running the following command. Replace [PATH] with the location of the JSON file that contains your credentials.

Obtain an authorization token using the command:

Copy the access token at somewhere safe.

 

Step 3: Integration with Node.js Application

Considering you have already a basic Node.js application ready, we will explain how to use google REST APIs.

In order to use video-intelligence, we need to install npm package containing client library. Open the command prompt in the project directory and install google cloud library using the following command

Once the package is installed, we will write a code providing local storage video URL to the function. This function will convert the video into the base64 format and pass to the google video intelligence API.

Code for Implementation

After giving the request some time (about a minute, typically), the same request returns annotation results in JSON format.

Congratulations! You’ve sent your first request to Cloud Video Intelligence API.

Note:- Google Video-Intelligence API is not a free service. You can get free credits for demo purpose.

You want any assitance or want to develop you application in Machine Learning you can always contact us here.

Resource- Google Video-Intelligence Docs

Facebook Comments