Sunday, October 11, 2020

Azure Cognitive Service

Cognitive Services are a set of machine learning algorithms that Microsoft has developed to solve problems in the field of Artificial Intelligence (AI). We can use these services to add AI capabilities in our application easily to provide more value to our customer without need of any data scientist. Cognitive Services brings AI within reach of every developer—without requiring machine-learning expertise. All it takes is an API call to embed the ability to see, hear, speak, search, understand and accelerate decision-making into your apps.


The Cognitive Services APIs are grouped into five categories.

1.       Vision: This is a Microsoft Cognitive Service to build custom image classifiers. Custom Vision makes it easier and faster to build, deploy and improve image classifiers with artificial intelligence and machine learning. This service features facial analysis, handwriting recognition, optical character recognition (OCR) from images and real-time video analyses.

2.       Speech: Through Azure’s speech cognitive services API, you can integrate speech processing capabilities into any app or service. So, regardless of speech style, geography or technical term, the application allows users to recognize everything that’s spoken and transcribe the text accordingly.

3.       Language: Language and context-based meaning are two of the most important features that define communication. Through the cognitive services language API, you can develop apps that understand a wide variety of text.

4.       Knowledge: Azure’s cognitive services offer some of the most comprehensive and accurate database creation and search tools available. The knowledge API can leverage or create resources to be integrated into apps and services with several other capabilities. For instance, a Q&A service can be used to scan vast amounts of content and text and quickly extract the most relevant information. So, no matter the question, you’re bound to find the answers you’re seeking.

In this blog I will explain what Vision Cognitive Services and how we can use this in our application. I will also create demo application.

What is Computer Vision?

Computer vision is part of Vision Cognitive Services. Azure's Computer Vision service gives you access to advanced algorithms that process images and return information based on the visual features you're interested in. For example, Computer Vision can determine whether an image contains adult content, find specific brands or objects, or find human faces.

We will create one demo application to understand it very well. I am using 3 azure services for this demo.

1.       Computer Vision Cognitive Services (djblogscomputervision)

2.       Storage account (djblogsstorageaccount)

3.       Web App (djblogsvisionapp)

This is the demo app diagram which we will build step by step and will save code in my GitHub repository



Computer Vision Cognitive Services

First, we will create computer vision cognitive service which help us to analyze the image and will give all image information as response. Then we will show that response data in our web app.

We need to follow below steps to create computer vision cognitive service.

1.       Go to azure portal https://portal.azure.com

 

2.       Once we login in portal then need to create Computer Vision.



3.       Click on create button it will open create Computer Vision form. I have filled form as below


4.       I have selected free pricing tier for this demo project. In free tier we can do only 20 API calls per minute. You can choose pricing tier based on your requirement but for demo project you can select free tier.

5.       Filled form as above then just click on Create. It will create Computer Vision endpoint and Keys which help us to consume the Computer Vision API.


6.       You can see in above screen got both API endpoint and keys. We will use then to call Computer Vision API from WebApp to analyze the image.

API Endpoint:  https://djblogscomputervision.cognitiveservices.azure.com

2 Keys: Confidential information

Now our Computer Vision API ready to consume. We will consume it from WebApp.

Storage account

We will use Storage account as database to save uploaded images from our WebApp. I am using storage account djblogsstorageaccount to save images. If you want to learn more about please take a look into this Whatis Azure Storage Account.

I am using already created storage account djblogsstorageaccount to save images in blob. Need follow steps to create block inside storage account.

1.       Go to azure portal https://portal.azure.com

2.       Once we login in portal you need to select the djblogsstorageaccount storage account.


3.       Now we add new images container inside blob containers to save images inside it.

 Now our Blob storage container ready for use.

Web App

As you know, we will create WebApp that will consume Computer Vision API. I had explained it in previous blog. How we can create WebApp. If you want to learn it in detail, please take a look into CreateWeb App.

Creating WebApp for upload image and display image information. Follow below steps to create it.

1.       Go to azure portal https://portal.azure.com

2.       Once we login in portal then need to create WebApp. It will open below form as below

3.       Once we click on Create, it will create WebApp. Then we will download WebApp publisher from azure portal and publish directly from visual studio.


WebApp URL: https://djblogsvisionapp.azurewebsites.net

4.       We will create .net core MVC application which will use both Storage Account and Computer Vision. We will store this information in WebApp configuration Application settings section. It will look like as below in azure portal.


5.       These Application settings consumed as Environment Variable in our C# code.

6.       In our code, I have created 3 projects inside one solution

a.       DJBlogs.ComputerVision (C# class library for Computer Vision API)

b.       ComputerVision (Console Application to test class library)

c.       WebApp (MVC .NET core application)  

I have used Microsoft.Azure.CognitiveServices.Vision.ComputerVision NuGet package to call vision API.


GitHub Code: https://github.com/deepakjoshiinfo/DJBlogs.ComputerVision.App

You can download code from GitHub.

4.       Once all set we will publish our code in Azure WebApp with help of publisher profile as below

Application URL: https://djblogsvisionapp.azurewebsites.net/


5.       Once application deployed on azure you will see all the images stored in Blob Storage account

6.       If you want to upload new image you need to click on Upload link. You need to choose the image from your local machine

 

7.       Once you click on upload button it will uploaded in blob storage. If you want to see image all information you need to click on image.


8.      When we click on man image it will show all information as below

 

You can try it by uploading your images which you want to analyze.

URL: https://djblogsvisionapp.azurewebsites.net/

Hope you have got little idea about Azure Cognitive Services. This demo application helps you to understand computer vision services developed by Microsoft for image analysis.   

Keep learning, keep sharing. Cheers

1 comment:

  1. Azure Cognitive Services are a set of cloud-based APIs and services provided by Microsoft. They enable developers to integrate AI capabilities into their applications, including tasks like natural language processing, computer vision, speech recognition, and more. What Windows Best These services empower applications to understand, interpret, and interact with users and their environments.

    ReplyDelete