Specify a face recognition model

This guide shows you how to specify a face recognition model for face detection, identification and similarity search using the Azure Face service.

The Face service uses machine learning models to perform operations on human faces in images. We continue to improve the accuracy of our models based on customer feedback and advances in research, and we deliver these improvements as model updates. Developers have the option to specify which version of the face recognition model they'd like to use; they can choose the model that best fits their use case.

The Azure Face service has three recognition models available. The models recognition_01 (published 2017) and recognition_02 (published 2019) are continually supported to ensure backwards compatibility for customers using FaceLists or PersonGroups created with these models. A FaceList or Persongroup will always use the recognition model it was created with, and new faces will become associated with this model when they are added. This cannot be changed after creation and customers will need to use the corresponding recognition model with the corresponding FaceList or PersonGroup.

You can move to later recognition models at your own convenience; however, you will need to create new FaceLists and PersonGroups with the recognition model of your choice.

The recognition_03 model (published 2020) is the most accurate model currently available. If you're a new customer, we recommend using this model. Recognition_03 will provide improved accuracy for both similarity comparisons and person-matching comparisons. Note that each model operates independently of the others, and a confidence threshold set for one model is not meant to be compared across the other recognition models.

Read on to learn how to specify a selected model in different Face operations while avoiding model conflicts. If you are an advanced user and would like to determine whether you should switch to the latest model, skip to the Evaluate different models section to evaluate the new model and compare results using your current data set.

Prerequisites

You should be familiar with the concepts of AI face detection and identification. If you aren't, see these guides first:

Detect faces with specified model

Face detection identifies the visual landmarks of human faces and finds their bounding-box locations. It also extracts the face's features and stores them for use in identification. All of this information forms the representation of one face.

The recognition model is used when the face features are extracted, so you can specify a model version when performing the Detect operation.

When using the Face - Detect API, assign the model version with the recognitionModel parameter. The available values are:

  • recognition_01
  • recognition_02
  • recognition_03

Optionally, you can specify the returnRecognitionModel parameter (default false) to indicate whether recognitionModel should be returned in response. So, a request URL for the Face - Detect REST API will look like this:

https://westus.api.cognitive.microsoft.com/face/v1.0/detect[?returnFaceId][&returnFaceLandmarks][&returnFaceAttributes][&recognitionModel][&returnRecognitionModel]&subscription-key=<Subscription key>

If you are using the client library, you can assign the value for recognitionModel by passing a string representing the version. If you leave it unassigned, a default model version of recognition_01 will be used. See the following code example for the .NET client library.

string imageUrl = "https://news.microsoft.com/ceo/assets/photos/06_web.jpg";
var faces = await faceClient.Face.DetectWithUrlAsync(imageUrl, true, true, recognitionModel: "recognition_01", returnRecognitionModel: true);

Identify faces with specified model

The Face service can extract face data from an image and associate it with a Person object (through the Add face API call, for example), and multiple Person objects can be stored together in a PersonGroup. Then, a new face can be compared against a PersonGroup (with the Face - Identify call), and the matching person within that group can be identified.

A PersonGroup should have one unique recognition model for all of the Persons, and you can specify this using the recognitionModel parameter when you create the group (PersonGroup - Create or LargePersonGroup - Create). If you do not specify this parameter, the original recognition_01 model is used. A group will always use the recognition model it was created with, and new faces will become associated with this model when they are added to it; this cannot be changed after a group's creation. To see what model a PersonGroup is configured with, use the PersonGroup - Get API with the returnRecognitionModel parameter set as true.

See the following code example for the .NET client library.

// Create an empty PersonGroup with "recognition_02" model
string personGroupId = "mypersongroupid";
await faceClient.PersonGroup.CreateAsync(personGroupId, "My Person Group Name", recognitionModel: "recognition_02");

In this code, a PersonGroup with ID mypersongroupid is created, and it is set up to use the recognition_02 model to extract face features.

Correspondingly, you need to specify which model to use when detecting faces to compare against this PersonGroup (through the Face - Detect API). The model you use should always be consistent with the PersonGroup's configuration; otherwise, the operation will fail due to incompatible models.

There is no change in the Face - Identify API; you only need to specify the model version in detection.

Find similar faces with specified model

You can also specify a recognition model for similarity search. You can assign the model version with recognitionModel when creating the face list with FaceList - Create API or LargeFaceList - Create. If you do not specify this parameter, the recognition_01 model is used by default. A face list will always use the recognition model it was created with, and new faces will become associated with this model when they are added to the list; you cannot change this after creation. To see what model a face list is configured with, use the FaceList - Get API with the returnRecognitionModel parameter set as true.

See the following code example for the .NET client library.

await faceClient.FaceList.CreateAsync(faceListId, "My face collection", recognitionModel: "recognition_03");

This code creates a face list called My face collection, using the recognition_03 model for feature extraction. When you search this face list for similar faces to a new detected face, that face must have been detected (Face - Detect) using the recognition_03 model. As in the previous section, the model needs to be consistent.

There is no change in the Face - Find Similar API; you only specify the model version in detection.

Verify faces with specified model

The Face - Verify API checks whether two faces belong to the same person. There is no change in the Verify API with regard to recognition models, but you can only compare faces that were detected with the same model.

Evaluate different models

If you'd like to compare the performances of different recognition models on your own data, you will need to:

  1. Create three PersonGroups using recognition_01, recognition_02, and recognition_03 respectively.
  2. Use your image data to detect faces and register them to Persons within these three PersonGroups.
  3. Train your PersonGroups using the PersonGroup - Train API.
  4. Test with Face - Identify on all three PersonGroups and compare the results.

If you normally specify a confidence threshold (a value between zero and one that determines how confident the model must be to identify a face), you may need to use different thresholds for different models. A threshold for one model is not meant to be shared to another and will not necessarily produce the same results.

Next steps

In this article, you learned how to specify the recognition model to use with different Face service APIs. Next, follow a quickstart to get started using face detection.