AI-900 Microsoft Azure AI Fundamentals – Describe features of computer vision workloads on Azure Part 2

  1. Lab – Computer Vision – Analyzing a Face

Hi, and welcome back. So in this chapter, we are going to see how to recognise a face using the Computer Vision API. So again, as an image, I’m going to go ahead and post this image onto the Computer Vision API. So over here, we’re going to be using the “Analyze Image” feature, which is available with the Computer Vision API.

So if I go ahead and scroll down, again, let’s go ahead and take the request URL. So I’m adding it over here. Next, we need our endpoint, so let me go ahead and scroll on top. Again, I’ll take the North Europe region, so let me replace it over here. Now, over here, in terms of the visual features that we require, here is where you can tell that we want to go ahead and basically analyse a face. So, if you scroll down, please keep in mind that this is a postmethod, so let’s go ahead and scroll down. So in terms of the optional visual features over here, we can go ahead and actually decide what we want to get back during the analysis phase of this particular service. So over here, we have something known as faces.

So over here, this will go ahead and detect if the faces are present or not. And if they are present, it will go ahead and generate the coordinates, the gender, and the age. So let’s go ahead and do that. So let me go ahead and say that I’d like to return faces with visual features. So let’s go ahead and take it. Let’s check out the postman tool. I’ll go ahead and just generate a new request. I’ll put it as a post request. Enter the request URL again in the headers; the concept is the same concept.

We have to go ahead and take the subscription key and place it over here. Go on to the computer vision service, copy the key onto the clipboard, and place it over here. Go on to the body of the request. Choose Binary. So I’ll choose my photo from my local system, right? So I’ve uploaded that image. Let me go ahead and hit send. So over here, it has returned the gender and the age as well. I’m very happy with the age return. And over here, you can see the bounding coordinates of the face itself. So these are the basic features that are available when it comes to the face feature with the Computer Vision API.

  1. A quick look at the Face service

Now, if you want to go ahead and see an example of what the Face Service can do, So again, you can go on to the vision section. Over here, you can go on to the face-to-face service. So over here, you can go ahead and scroll down. So you have phase detection, you have face verification, and over here, you have something noticed in perceived emotion recognition. So first, let me go on to face detection. So over here, there is only one image in place.

Now I can go ahead and browse for an image that I have on my local system. So let me go ahead and do that. So over here, let me go ahead and browse for an image that I have on my local machine. So it should go ahead and actually detect the face within the image itself. Over here, you can see the bounding coordinates of the face itself. Now, if I go on to perceived emotion recognition, over here, let me go ahead and again browse for the same image. So I’ll go ahead and browse for the same image. So over here, in addition to detecting my face, it’s also going ahead and trying to understand any sort of emotional attributes of my face attributes.

So, for example, it can go and detect the happiness level. Over here, it is giving the impression that mostly it is a neutral emotion when it comes to my face, and that’s fine. So over here, you can see all of the facial attributes that have been detected by this phase of the API. So over here, you can already see there is a lot of intelligence in the service itself. You can go ahead and submit an image to the service, and the service has the ability to go ahead and understand everything about that image and give you relevant information. Now I can go on to face verification. So over here, face verification can go ahead and take multiple images and tell you if they belong to the same person. So over here, let me go ahead and browse for one image that I have, and over here, let me go ahead and browse for the other image. So I have both the images over here, and in the verification result, it says these two faces belong to the same person. And it also has a high confidence rating. As a result, the closer you are to one, the more confident it is in its outcome. So you can see a lot of features available with the Face Service here. You.

  1. Lab – Face API – Using Visual Studio 2019

Hi, and welcome back. Now, in the last chapter, I showed you how you can use the Face feature, which is available with the Computer Vision API. Now we are going to look at the Face API. So the Face API is a separate API that is available as part of the Azure Cognitive Services suite. So for that, we have to go ahead and create a new resource in Azure that’s based on the Face service. So in Azure, in all resources, let me go ahead and click on Add. Over here in the marketplace, I can go ahead and search for and choose Face so that we can go ahead and create a resource based on the Face service. Over here, let me go out and choose my resource group. Let me go ahead and just choose a region. Let me go out and give you a name. So again, it has to be unique. Now, in the pricing tier, again, we can go ahead and choose the free pricing tier, since we’re not making that many calls per minute. Allow me to speak about taxes. I’ll go on to review and create. And let me go ahead and hit on Create. Now I’ll show you how to use the Face API from a. Net programme in this chapter.

Again, it’s the same basic way that you invoke a service similar to that of the Computer Vision API. I’ll also show you how to invoke the Face API from the Postman tool. So here I can see that I already have the resource in place in my Azure Storage account in my data container. So I’ve gone ahead and uploaded the image of myself onto this container in the storage account. So we are going to go ahead and use this same image. Now over here, I have my Visual Studio programme in place, which is basically my netprogram in place in Visual Studio 2019. Now, I’ve already added the codeover here; if I go to Tools, then to the new Get Package Manager, Again, this is just for those who are net developers. If I proceed to the Install section and manage NuGet packages for this solution. So over here, I’ve gone ahead and actually installed Microsoft Azure Cognitive Services. If I go ahead and show it over here, this is the package that I’ve gone ahead and installed. So it’s very easy to go ahead and actually instal this package.

So if you actually go on to the browse section, you can go ahead and search it over here. Just ensure the other two checkboxes include “pre-release” because this particular package is in the preview state. and you can go ahead and instal this package for your solution. Now, going on to the program: So over here, again, we have a subscription key that will authorize this programme to go ahead and use the Face API. We also have the face-end point. So, again, this is similar to the usage of the Computer Vision API. So let’s go ahead and change these values. So, returning to our Face resource, we’ll proceed to the keys and the end point. So let me go ahead and take either one of the keys copied onto the clipboard again. Let’s copy it over here. Let’s go back to the endpoint. Let me go ahead and copy it. Go over to the programme and replace it here. Then we have the URL of the image in the storage account.

So I’ll go onto my storage account, and I’ll go onto the image. I’ll go ahead and take the URL. I’ll go on to my program. I’ll replace it over here. Now, in this program, I’m actually making use of the Face classes to go ahead and actually interact with the Face API. Again, I’m not going into detail on the programme itself, but over here, I just want to let you know that, similar to getting the visual features in the Computer Vision API over here, I’m asking to go ahead and get the face attributes. So if the Face API does detect that there is a face in the image that is given to it, I want to go ahead. I’m telling it to go ahead and get me the gender, the age, and other characteristics of the face itself. And then I’m just going ahead and scrolling down. And then I’m just going ahead and writing some information onto the console.

So I just want to go ahead and see what gender I have, whether I am happy, what my age is, and whether I am smiling. So let me go ahead and run this program. So, not as happy, not as smiling, and the age is a little older than what we got from the Computer Vision API. But again, over here, you can see you are getting much more features when it comes to what this service can detect about a face. So, again, when it comes to the features of being happy or smiling, these are all on a scale of zero to one. So, obviously, the closer it is to one, the more confident it is about whether or not that feature was detected accurately in the face. But in this chapter, I want to show you that you can go ahead and use the Face API to get additional features about a face.

  1. Lab – Face API – Using POSTMAN tool

Now, in the last chapter, we saw how to use the phase API from a Net program. Now over here, I’ll show you how to use the PATH API from the Postman Tool. Now, when it comes to the phase API itself, there are a lot of features that are available with this API itself. So the basic service of Detect has the capability of basically detecting human faces within an image.

You can also find a similar set of faces. You can go ahead and group faces together. You can go ahead and identify a face within a collection of faces, in an image, et cetera. So there are a lot of features available with the face service itself. So we are going to start with the detection of a face within an image. Now over here, in terms of the detection of the face, over here you have the description of what this feature actually does. Over here, you can see some of the restrictions that are applicable to the images that you submit via the Face API. We’ll go ahead and scroll down. This is, once again, a post method. If you go on to the request URL, again, you have the ability to go ahead and detect a face, and you have a lot of parameters in place. We are going to focus on the parameter of returning the face attributes.

So when you go ahead and return the face attributes, you can go ahead and get various face attributes such as the age, the gender, the head pose, the smile, et cetera. So again, notepad, this is the basic URL for the “detect” feature of the face API. I’ve gone ahead and again added the North Europe endpoint. And over here, in terms of detection, I’m saying, “Please go ahead and return these phase attributes.” So let’s go ahead and attach this to the Postman Tool. So over here in the Postman tool, for a request, let me go ahead and choose a post request. Enter the URL again in the headers. Let’s go ahead and take the subscription key. Let’s get the value from the face API. So I’ll go ahead and take the key. Remember, this is not the computer vision API. This is the face of API. I’ll go ahead and add it as a value over here. Now, in the body, again, let me go ahead and choose binary. Let me go ahead and select the image. That’s my face image from my local system. Let me go ahead and hit on Send. Now over here, you can see that after sending the request, we’ve actually got an error message. So let’s go back to the documentation for the API. So this is very useful. Now on this same page, which tells you how to invoke the API, So this is available for all of the APIs if you go ahead and scroll down.

So please come over here if you receive a different response code. So normally the response code should be 200, so if you get Another response code is 400, which indicates that an error has occurred and provides the error code as well as the message description. So if I go ahead and just scroll down, So over here, you can see the error message that we got. So over here, it’s saying that for a local image, the content type should be application slash. Octet stream. So let’s go ahead and actually do that. So let us go on to the Postman tool over here in the headers. So I think that by default, let’s go ahead and just click on this. Eight are hidden so that we can actually expose all of the hidden headers. So by default, there will be some headers that will be attached by the postman tool. So that’s the fundamental normal header information. So over here, you can see that in the content type, it is automatically putting it as an image JPEG.

So over here, we have to go ahead and change this. Now, in order to go ahead and change this, let me go ahead and deselect this content type, and then let me go ahead and add. It has my own key over here, so content Type and over here, I can see I have an application if I just go ahead and type in applications. Octet stream. So let me go ahead and choose that. Now let’s go ahead and click on “Send.” And now you can see that you’re getting the information you desired. So, once again, you are seeing the gender you are seeing. The smile. You are seeing the head pose. You are seeing my age. So here we are again. So I’ve shown you how to invoke the Face API from the Postman tool. I’ve also shown you that if you do get an error when it comes to invoking APIs in the Postman tool, Just go to the same page for the API, and you will be able to see the various ways in which you can go ahead and rectify these issues.

  1. Lab – Face Verify API – Using POSTMAN tool

Hi, and welcome back. Now in this chapter, we are going to go ahead and look at the verify feature, which is available as part of the Face API. Now the entire purpose of this verify feature is to go ahead and verify whether two faces belong to the same person or if one face belongs to a person itself. So this is something that you can also do with the help of the Face API. So if I go ahead and scroll down, again, this is a post method. Over here, we have the request URL. When it comes to the body of the request, we must proceed as if we were submitting two faces to this API. The API will then compare the faces and tell us whether they belong to the same person. To proceed with submitting two faces, we must first obtain the face ID of each face in each image. So this can be done with the help of the Face Detect feature, which is part of the Face API. So that’s step number one.

So we have to go ahead and first get the faceIDs, and then we can go ahead and submit those faceIDs onto the verify API, and then the verify API will tell us whether the faces belong to the same person. So that is what we are going to do first. So let me go on to the “detect” feature that we have. So over here, let me go ahead and scroll down. So we’ve already seen this before. So the images I’m going to use again are: I have my image, which is my face, and I have another image as well. So we’re going to go ahead and compare both of these images. So I’ll let you go ahead and get the face ID first. So again, let me go ahead and take the URL. So I’ll paste it over here again. Take North Europe. I don’t need to add any sort of features over here; I just want to go ahead and get the face ID. So let me use the postman tool. So over here, let me go on to a new tab to post the request again, do detect headers, and then I’ll just take the headers for one of my previous requests. We had done this early on.

So I can go ahead and use the same key and the same value, right? Let me go on to the body of the request. Let me go on to binary. Let me go ahead and select one of the files that I have. Let me go on to headers. Let me ensure the content type is also modified. So remember, the content type has to be “application octet stream.” Let me go ahead and hit on Send. So over here, I’ve got the Face ID of the first image, so let me go ahead and just place it over here. Now, with the same request, let me go onto the body again, and let me go ahead and just remove this image, and let’s go ahead and select the other image that I have. So over here, I already selected this image. Let me go ahead and select the other image. Click on “open.” Let me go ahead and hit on Send. So I’ve got the other face ID as well.

All right, so now let’s go on to the next API. So let’s go back to verify. So let’s go ahead and scroll down. So let’s take the Verify endpoint. So I can go ahead and use the same endpoint over here. This is also a post request, so what I can do is let me go ahead and create a new request. Again, a post request to Verify over here, please allow me to take the subscription key. Let’s go ahead and take the value as well. Right now, I have to go on to the body of the request. So, in terms of the body of the request, if you scroll down, over here, it gives you an example of comparing a face to a person ID. But what we really want to do is compare two Face IDs. So what I’ll do is let me just go ahead and copy this and paste it into the Postman tool. So I’ll choose “Raw” because I want to go ahead and add JSON data over here. I want to send JSON data onto the server, including the closing brackets. Again, if I go ahead and scroll up, So the field is face ID one and phase ID two. So let me go out and ensure that I replace it over here. So this should be phase ID one and face ID one. Right. And let me go out and just copy this to make Face ID 2.

And let’s go ahead and copy the FaceID that was returned in the previous request. So I’ll replace the other one as well. So everything seems to be fine. Let’s go ahead and hit on Send. So, because of the invalid subscription key, we’re getting accesstonight again; let me return to headers. So I need to go ahead and add that subscription key over here. So let me go ahead and add the subscription key, and let me go ahead and hit Send now. So the is identical is coming true with a high degree of certainty. So you can go ahead and use the VerifyAPI over here to go ahead and verify if two faces belong to the same person. Remember, over here, you’ll first go ahead and use the Detect API to get the face ID. And then you can go ahead and compare both of the face IDs together.

img