Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Migration from 0.6 to 1.2.0
  • Loading branch information
ahodkov committed Mar 30, 2023
commit 8ca2b9c246c981f34faf28fc574b63df49686973
192 changes: 179 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,45 @@
CompreFace Python SDK makes face recognition into your application even easier.

# Table of content
- [CompreFace Python SDK](#compreface-python-sdk)
- [Table of content](#table-of-content)
- [Requirements](#requirements)
- [CompreFace compatibility matrix](#compreface-compatibility-matrix)
- [Installation](#installation)
- [Usage](#usage)
- [Initialization](#initialization)
- [Adding faces into a face collection](#adding-faces-into-a-face-collection)
- [Recognition](#recognition)
- [Webcam demo](#webcam-demo)
- [Reference](#reference)
- [CompreFace Global Object](#compreFace-global-object)
- [CompreFace Global Object](#compreface-global-object)
- [Methods](#methods)
- [Options structure](#options-structure)
- [Face Recognition Service](#face-recognition-service)
- [Recognize Faces from a Given Image](#recognize-faces-from-a-given-image)
- [Recognize Faces from a Given Image, Embedding](#recognize-faces-from-a-given-image-embedding)
- [Get Face Collection](#get-face-collection)
- [Add an Example of a Subject](#add-an-example-of-a-subject)
- [List of All Saved Examples of the Subject](#list-of-all-saved-examples-of-the-subject)
- [Delete All Examples of the Subject by Name](#delete-all-examples-of-the-subject-by-name)
- [Delete an Example of the Subject by ID](#delete-an-example-of-the-subject-by-id)
- [Delete Multiple Examples](#delete-multiple-examples)
- [Verify Faces from a Given Image](#verify-faces-from-a-given-image)
- [Verify Faces from a Given Image, Embedding](#verify-faces-from-a-given-image-embedding)
- [Get Subjects](#get-subjects)
- [Add a Subject](#add-a-subject)
- [List Subjects](#list-subjects)
- [Rename a Subject](#rename-a-subject)
- [Delete a Subject](#delete-a-subject)
- [Delete All Subjects](#delete-all-subjects)
- [Face Detection Service](#face-detection-service)
- [Detect](#detect)
- [Face Verification Service](#face-verification-service)
- [Verify](#verify)
- [Face Detection Service](#face-detection-service)
- [Detect](#detect)
- [Face Verification Service](#face-verification-service)
- [Verify Image](#verify-image)
- [Verify Embedding](#verify-embedding)
- [Contributing](#contributing)
- [Report Bugs](#report-bugs)
- [Submit Feedback](#submit-feedback)
- [Report Bugs](#report-bugs)
- [Submit Feedback](#submit-feedback)
- [License info](#license-info)

# Requirements
Expand Down Expand Up @@ -236,6 +243,10 @@ If the option’s value is set in the global object and passed as a function arg

```python

class PredictionCountOptionsDict(TypedDict):
prediction_count: int


class DetProbOptionsDict(TypedDict):
det_prob_threshold: float

Expand All @@ -246,6 +257,12 @@ class ExpandedOptionsDict(DetProbOptionsDict):
face_plugins: str


class SavedObjectOptions(TypedDict):
page: int
size: int
subject: str


class AllOptionsDict(ExpandedOptionsDict):
prediction_count: int

Expand Down Expand Up @@ -286,7 +303,7 @@ Recognizes all faces from the image.
The first argument is the image location, it can be an url, local path or bytes.

```python
recognition.recognize(image_path, options)
recognition.recognize_image(image_path, options)
```

| Argument | Type | Required | Notes |
Expand Down Expand Up @@ -359,6 +376,47 @@ Response:
| execution_time | object | execution time of all plugins |
| plugins_versions | object | contains information about plugin versions |

### Recognize Faces from a Given Image, Embedding

Determine similarities between input embeddings and embeddings within the Face Collection.

```python
recognition.recognize_embedding(self, embeddings: list, options: PredictionCountOptionsDict = {})
```

| Argument | Type | Required | Notes |
| ------------------ | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| embeddings | list | required | An input embeddings. The length depends on the model (e.g. 512 or 128) |
| options | object | optional | `PredictionCountOptionsDict` object can be used in this method. See more [here](#options-structure). |

Response:

```json
{
"result": [
{
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
"similarities": [
{
"subject": "John",
"similarity": 0.55988
},
"..."
]
},
"..."
]
}
```

| Element | Type | Description |
|--------------|--------|--------------------------------------------------------------------------------------------|
| result | array | an array that contains all the results |
| embedding | array | an input embedding |
| similarities | array | an array that contains results of similarity between the embedding and the input embedding |
| subject | string | a subject in which the similar embedding was found |
| similarity | float | a similarity between the embedding and the input embedding |

### Get Face Collection

```python
Expand Down Expand Up @@ -411,8 +469,11 @@ Response:
To retrieve a list of subjects saved in a Face Collection:

```python
face_collection.list()
face_collection.list(options)
```
| Argument | Type | Required | Notes |
| ------------------ | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| options | object | optional | `SavedObjectOptions` object can be used in this method. See more [here](#options-structure). |

Response:

Expand All @@ -424,14 +485,22 @@ Response:
"subject": <subject>
},
...
]
],
"page_number": int,
"page_size": int,
"total_pages": int,
"total_elements": int
}
```

| Element | Type | Description |
| -------- | ------ | ----------------------------------------------------------------- |
| image_id | UUID | UUID of the face |
| subject | string | <subject> of the person, whose picture was saved for this api key |
| page_number | integer | page number |
| page_size | integer | **requested** page size |
| total_pages | integer | total pages |
| total_elements | integer | total faces |

#### Delete All Examples of the Subject by Name

Expand Down Expand Up @@ -486,12 +555,40 @@ Response:
| image_id | UUID | UUID of the removed face |
| subject | string | <subject> of the person, whose picture was saved for this api key |


#### Delete Multiple Examples

To delete several subject examples

```python
face_collection.delete_multiple(image_ids)
```
| Argument | Type | Required | Notes |
| --------- | ------ | -------- | ------------------------------------------------------------
| image_ids | list | required | list of str or UUID of the removing face |

Response:

```
{
"image_id": <image_id>,
"subject": <subject>
}
```

| Element | Type | Description |
| -------- | ------ | ----------------------------------------------------------------- |
| image_id | UUID | UUID of the removed face |
| subject | string | <subject> of the person, whose picture was saved for this api key |

If some image ids are not exists, they will be ignored

#### Verify Faces from a Given Image

*[Example](examples/verification_face_from_image.py)*

```python
face_collection.verify(image_path, image_id, options)
face_collection.verify_image(image_path, image_id, options)
```

Compares similarities of given image with image from your face collection.
Expand Down Expand Up @@ -566,6 +663,41 @@ Response:
| execution_time | object | execution time of all plugins |
| plugins_versions | object | contains information about plugin versions |


#### Verify Faces from a Given Image, Embedding

```python
face_collection.verify_embeddings(embedding, image_id)
```

Compare input embeddings to the embedding stored in Face Collection.


| Argument | Type | Required | Notes |
| ------------------ | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| embeddings | array | required | An input embeddings. The length depends on the model (e.g. 512 or 128) |
| image_id | str or UUID | required | An id of the source embedding within the Face Collection |

Response:

```json
{
"result": [
{
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
"similarity": 0.55988
},
"..."
]
}
```

| Element | Type | Description |
|-------------|--------|------------------------------------------------------------------------------|
| result | array | an array that contains all the results |
| embedding | array | a source embedding which we are comparing to embedding from Face Collection |
| similarity | float | a similarity between the source embedding and embedding from Face Collection |

### Get Subjects

```python
Expand Down Expand Up @@ -614,6 +746,7 @@ Returns all subject related to Face Collection.
subjects.list()
```


Response:

```json
Expand Down Expand Up @@ -792,10 +925,10 @@ A source image should contain only one face which will be compared to all faces

**Methods:**

### Verify
### Verify Image

```python
verify.verify(source_image_path, target_image_path, options)
verify.verify_image(source_image_path, target_image_path, options)
```

Compares two images provided in arguments. Source image should contain only one face, it will be compared to all faces in the target image.
Expand Down Expand Up @@ -903,6 +1036,39 @@ Response:
| execution_time | object | execution time of all plugins |
| plugins_versions | object | contains information about plugin versions |

### Verify Embedding

```python
verify.verify_embedding(source_embeddings, targets_embeddings)
```

Determine similarities between an input source embedding and input target embeddings.

| Argument | Type | Required | Notes |
| ------------------ | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| source_embeddings | list | required | An input embeddings. The length depends on the model (e.g. 512 or 128) |
| targets_embeddings | list | required | An array of the target embeddings. The length depends on the model (e.g. 512 or 128) |

Response:

```json
{
"result": [
{
"embedding": [0.0627421774604647, "...", -0.0236684433507126],
"similarity": 0.55988
},
"..."
]
}
```

| Element | Type | Description |
|-------------|--------|--------------------------------------------------------------------|
| result | array | an array that contains all the results |
| embedding | array | a target embedding which we are comparing to source embedding |
| similarity | float | a similarity between the source embedding and the target embedding |

# Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
Expand Down
3 changes: 3 additions & 0 deletions compreface/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
from .detect_face_from_image import DetectFaceFromImageClient
from .verify_face_from_image import VerifyFaceFromImageClient
from .subject_client import SubjectClient
from .recognize_face_from_embeddings import RecognizeFaceFromEmbeddingClient
from .verification_face_from_embeddings import VerificationFaceFromEmbeddingClient
from .verify_face_from_embeddings import VerifyFaceFromEmbeddingClient
Loading