Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2979994
codegen update
Han-msft Aug 27, 2024
269e116
Update client _patch
Han-msft Aug 27, 2024
6f89e05
Update version
Han-msft Aug 27, 2024
ed8876b
Update assets
Han-msft Aug 27, 2024
4a19c27
Update codegen
Han-msft Aug 28, 2024
492b67b
Sample for large face list
Han-msft Aug 28, 2024
0fc87db
Add LPG sample
Han-msft Aug 28, 2024
ae592ed
Update codegen
Han-msft Sep 2, 2024
d7a0393
Remove unused testcase
Han-msft Sep 2, 2024
99837e6
Add findsimilar test
Han-msft Sep 2, 2024
9315435
Add identify test
Han-msft Sep 3, 2024
453f812
Remove FL and PG
Han-msft Sep 6, 2024
2cf5745
Fix test
Han-msft Sep 6, 2024
d29b753
Update codegen
Han-msft Sep 9, 2024
c5d7ed8
Remove _operations
Han-msft Sep 9, 2024
a1d365e
Add changelog
Han-msft Sep 9, 2024
0ec1f1e
Codegen
Han-msft Sep 9, 2024
b96d74a
Add new content to README
Han-msft Sep 10, 2024
b0f98e5
Merge remote-tracking branch 'origin/main' into hachiang/face-v1.1
Han-msft Sep 13, 2024
3c2367c
Regen
Han-msft Sep 13, 2024
5fd08b6
Update model enum
Han-msft Sep 19, 2024
3b4be0b
Update typo in generated test
Han-msft Sep 19, 2024
8c39cc2
Add enum breaking change schangelog
Han-msft Sep 24, 2024
af693ed
Merge remote-tracking branch 'origin/main' into hachiang/face-v1.1
Han-msft Oct 9, 2024
e2cb5ac
update codegen
Han-msft Oct 9, 2024
6900326
Fix customization
Han-msft Oct 9, 2024
efb967b
Suppress verifytypes
Han-msft Oct 9, 2024
3d21d99
Update to latest tsp
Han-msft Oct 9, 2024
fc3fb85
Pause verifytypes
Han-msft Oct 9, 2024
7d58902
Update release date
Han-msft Oct 22, 2024
4fa8355
Update date
Han-msft Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new content to README
  • Loading branch information
Han-msft committed Sep 10, 2024
commit b96d74a454ce9f18aac1b6f45abe13f8238b770a
121 changes: 121 additions & 0 deletions sdk/face/azure-ai-vision-face/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The Azure AI Face service provides AI algorithms that detect, recognize, and ana
- Liveness detection
- Face recognition
- Face verification ("one-to-one" matching)
- Face identification ("one-to-many" matching)
- Find similar faces
- Group faces

Expand Down Expand Up @@ -130,6 +131,18 @@ face_client = FaceClient(endpoint, credential)
- Finding similar faces from a smaller set of faces that look similar to the target face.
- Grouping faces into several smaller groups based on similarity.

### FaceAdministrationClient

`FaceAdministrationClient` is provided to interact with the following data structures that hold data on faces and
person for Face recognition:

- `large_face_list`: It is a list of faces which can hold faces and used by [find similar faces][find_similar].
- It can up to 1,000,000 faces.
- Training (`begin_train()`) is required before calling `find_similar_from_large_face_list()`.
- `large_person_group`: It is a container which can hold person objects, and is used by face recognition.
- It can up to 1,000,000 person objects, with each person capable of holding up to 248 faces. The total person objects in all `large_person_group` should not exceed 1,000,000,000.
- For [face verification][face_verification], call `verify_from_large_person_group()`.
- For [face identification][face_identification], training (`begin_train()`) is required before calling `identify_from_large_person_group()`.

### FaceSessionClient

Expand All @@ -139,12 +152,23 @@ face_client = FaceClient(endpoint, credential)
- Query the liveness and verification result.
- Query the audit result.

### Long-running operations

Long-running operations are operations which consist of an initial request sent to the service to start an operation,
followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has
succeeded, to get the result.

Methods that train a group (LargeFaceList or LargePersonGroup) are modeled as long-running operations.
The client exposes a `begin_<method-name>` method that returns an `LROPoller` or `AsyncLROPoller`. Callers should wait
for the operation to complete by calling `result()` on the poller object returned from the `begin_<method-name>` method.
Sample code snippets are provided to illustrate using long-running operations [below](#examples "Examples").

## Examples

The following section provides several code snippets covering some of the most common Face tasks, including:

* [Detecting faces in an image](#face-detection "Face Detection")
* [Identifying the specific face from a LargePersonGroup](#face-recognition-from-largepersongroup "Face Recognition from LargePersonGroup")
* [Determining if a face in an video is real (live) or fake (spoof)](#liveness-detection "Liveness Detection")

### Face Detection
Expand Down Expand Up @@ -192,6 +216,103 @@ with FaceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) as face_c
print(f"Face: {face.as_dict()}")
```

### Face Recognition from LargePersonGroup

Identify a face against a defined LargePersonGroup.

First, we have to use `FaceAdministrationClient` to create a `LargePersonGroup`, add a few `Person` to it, and then register faces with these `Person`.

```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.vision.face import FaceAdministrationClient, FaceClient
from azure.ai.vision.face.models import FaceDetectionModel, FaceRecognitionModel


def read_file_content(file_path: str):
with open(file_path, "rb") as fd:
file_content = fd.read()

return file_content


endpoint = "<your endpoint>"
key = "<your api key>"

large_person_group_id = "lpg_family"

with FaceAdministrationClient(endpoint=endpoint, credential=AzureKeyCredential(key)) as face_admin_client:
print(f"Create a large person group with id: {large_person_group_id}")
face_admin_client.large_person_group.create(
large_person_group_id, name="My Family", recognition_model=FaceRecognitionModel.RECOGNITION_04
)

print("Create a Person Bill and add a face to him.")
bill_person_id = face_admin_client.large_person_group.create_person(
large_person_group_id, name="Bill", user_data="Dad"
).person_id
bill_image_file_path = "./samples/images/Family1-Dad1.jpg"
face_admin_client.large_person_group.add_face(
large_person_group_id,
bill_person_id,
read_file_content(bill_image_file_path),
detection_model=FaceDetectionModel.DETECTION_03,
user_data="Dad-0001",
)

print("Create a Person Clare and add a face to her.")
clare_person_id = face_admin_client.large_person_group.create_person(
large_person_group_id, name="Clare", user_data="Mom"
).person_id
clare_image_file_path = "./samples/images/Family1-Mom1.jpg"
face_admin_client.large_person_group.add_face(
large_person_group_id,
clare_person_id,
read_file_content(clare_image_file_path),
detection_model=FaceDetectionModel.DETECTION_03,
user_data="Mom-0001",
)
```

Before doing the identification, we need to train the LargePersonGroup first.
```python
print(f"Start to train the large person group: {large_person_group_id}.")
poller = face_admin_client.large_person_group.begin_train(large_person_group_id)

# Wait for the train operation to be completed.
# If the training status isn't succeed, an exception will be thrown from the poller.
training_result = poller.result()
```

When the training operation is completed successfully, we can identify the faces in this LargePersonGroup through
`FaceClient`.
```python
with FaceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) as face_client:
# Detect the face from the target image.
target_image_file_path = "./samples/images/identification1.jpg"
detect_result = face_client.detect(
read_file_content(target_image_file_path),
detection_model=FaceDetectionModel.DETECTION_03,
recognition_model=FaceRecognitionModel.RECOGNITION_04,
return_face_id=True,
)
target_face_ids = list(f.face_id for f in detect_result)

# Identify the faces in the large person group.
result = face_client.identify_from_large_person_group(
face_ids=target_face_ids, large_person_group_id=large_person_group_id
)
for idx, r in enumerate(result):
print(f"----- Identification result: #{idx+1} -----")
print(f"{r.as_dict()}")
```

Finally, use `FaceAdministrationClient` to remove the large person group if you don't need it anymore.
```python
with FaceAdministrationClient(endpoint=endpoint, credential=AzureKeyCredential(key)) as face_admin_client:
print(f"Delete the large person group: {large_person_group_id}")
face_admin_client.large_person_group.delete(large_person_group_id)
```

### Liveness detection
Face Liveness detection can be used to determine if a face in an input video stream is real (live) or fake (spoof).
The goal of liveness detection is to ensure that the system is interacting with a physically present live person at
Expand Down