Face API Cognitive Service Day 3: Face Identification using Face API

Posted by


This article series is a complete end to end tutorial that will explain the concept of face recognition and face detection using modern AI based Azure cognitive service i.e. Azure’s Face API service.


In the last two articles on learning Azure Face API Cognitive service, we learned how to setup Azure account, create Face API on Azure portal and test the services created. We learned the use of Face API SDK and how we can perform the needed operations from code itself. In this article we’ll explore how face identification can be done and what all services are involved to achieve this. We’ll create models and train them and see the result. So, a lot of machine learning involved.

Tutorial Series

The entire series on learning Face API cognitive services is divided in to four parts. The first part focuses on Azure Functions, Serverless computing and creating and testing Face API on Azure Portal.

The second part explains the use of Face API SDK. The third part will be focused on face identification, where person groups will be created, and identification of faces would be done via training the models i.e. via machine learning techniques. The fourth part is the most interesting part that gives a walkthrough of Face classification application which performs face detection, identification, grouping and finding look alike faces. Following is the four-part series.

  1. Face API Cognitive Service Day 1: Face API on Azure Portal.
  2. Face API Cognitive Service Day 2: Exploring Face API SDK.
  3. Face API Cognitive Service Day 3: Face Identification using Face API.
  4. Face API Cognitive Service Day 4: Face classification app using Face API.

Face Identification

In the last two articles, we saw face detection. In this section, we’ll focus on face identification and check the capabilities of Face API to identify the faces of the persons. In this section, we’ll see what all services we can write to perform face identification. We’ll test the services using Postman and in the next section, we’ll walk through a live face identification application.

Before we look at the individual operations in detail, it’s important for us to first understand the high-level structure and the workflow of how everything fits together. The first thing we need to do is to create a person group. The Face API gives us all the CRUD operations. It gives us all these operations for managing person groups. Once our person group is created, we can add n number of persons to that person group. After we add a person to a person group, then we add n number of faces to each person. Once we’ve added as many persons and faces to our person group that we want, we then invoke the Face API method to train our person group. Once our person group is trained, we’re ready to do face identification. Face identification always starts with face detection. You’ve already seen face detection. The key result is that we get a unique faceId for each face in face detection. Once we invoke detection, we can finally invoke face identification using the results of our face detection calls along with the person group we want to use for face identification. Let’s do that step by step.

Creating A Person Group

I have used some settings in the Postman to save my base URL i.e. https://centralindia.api.cognitive.microsoft.com/face/v1.0 and the secret key. So I’ll use the keyword {{base-url}} and {{face-api-key}} for URL and key respectively. You can use the base URL and the key you have in place of my keywords.

Make a pull request in the Postman for actions persongroups/1 appended to base URL as shown below. In the body, provide the raw json telling the name of the person group i.e. in my case “family” and the userData as a description of the person group. The json should be like following.


“name”: “family”,

“userData”: “family person group”


In the headers section, provide two keys i.e. Ocp-Apim-Subscription-Key and Content-Type and their values as your API key and application/json respectively. Hit the send button. Once you hit the send button, you get the response as 200 i.e. OK that means the person group is created.

Get A Person Group

We can check the crated person group by making a get call to the API at https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1

And you get the created person group with a person group id, name, and user data. In the next step, we’ll add a few persons to the person group.

Create Person

In the person groups created, append the URL with “persons” and in the body section, provide the name and user data of the function as below.


“name” : “Akhil Mittal”,

“userData” : “Author”


Keep the headers same i.e. providing key and content type and hit send button. Make sure the HTTP verb is Post. We get the response with a created person having a person id under person group 1.

Get Person

You can get the person with the id of the person that we received in the last step. Make a Get call to the API as https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1/persons<personid>.

We get the json response with personId, name and userData and an additional field that says an array of persistedFaceIds. Since we have not created any face for this person so that the field remains empty.

Get all Person

If you wish to get the list of all the persons you created for that particular person group, just name a Get call to the API at https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1/persons/

This will get you all the persons created in the JSON response under the person group having Id as 1.

Create Face for the Person

Time to create the face of the person i.e. the persisted face for the created person. Since you have the person id of the created person for which we want to create a persisted face. We’ll make a call to the API as https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1/persons/<personId>/persistedFaces.

In the body tag, provide a raw json that contains the URL of the person’s face i.e. the image of the person whose face has to be created.


“url”: “https://www.codeproject.com/script/Membership/Uploads/7869570/Akhil.png&#8221;


Following is the image of the person for which the URL is given,

Now, make a POST request with these configurations and make sure your header data has key and content-type defined. Hit Send button. Once we get the response, we that the response contains the json that has “persistedFaceId” that means the person’s face is created and a corresponding Id is returned.

Now if you again make the get request for that person, you’ll also get the persisted face id attribute having value for that person’s face as shown below.

Train the Person Group

It’s time to train the person group. Since we got the person group, person and his face. We’ll train our model and then perform face identification for that person. Just append train to persongroups/<id> URL and make a POST request as https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1/persons/train.

Once done, we’ll get the response as 200 i.e. Accepted.

Check Training Status

You can check the training status by making a Get request to the URL https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/1/persons/training.

We see here in the following image that we get the training status as succeeded. That means the person group is trained now to perform face identification operations.

Let’s do that in the next step.


I have uploaded the following image on the public URL that has my friend and me.

  1. Make a detect call to the uploaded image as we did initially and when we get the response, we wee the JSON for two faces returned one for my friend and another for mine.

  1. Now, since our person group is trained we can send an identify request to the base-URL. In the body, provide the json with person group id and the faces we got in the detect call in last operations.


    “personGroupId” : “1”,

    “faceIds” : [





Once we hit the send button and make that POST request. We get the response for both the provided faces but only one face has candidates that are telling the personId and the confidence level that the identified person is there in the person group or not. It seems to be working. Here we made a request for identification for two persons, but we got the response for only one that is my face because my face is already there in the person’s list of the created person group and our model is trained to process that. The response here is returned with the confidence level value which means that this is the level of confidence the API has that the identified person is there in the person group.

In the next section, we’ll go through a running application having all these operations and the visual view of the operations.


Till this article from we explored the capabilities of Azure Face API i.e. one of the Azure’s cognitive service. The API is quite intelligent and strong to leverage the AI and machine learning capabilities and perform the actions. We saw in detail how to create an Azure account, how to create a Face API and make it up and running. We saw how CRUD operations could be performed over the Face API for person groups, persons and faces. We performed face identification and model training as well.


  1. https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Vision.Face/
  2. https://azure.microsoft.com/en-in/services/cognitive-services/face/
  3. https://centralindia.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.