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
Prev Previous commit
Added detect_faces params
  • Loading branch information
ahodkov committed Apr 5, 2023
commit b7d9da563b1bd8a64270032e18e696a6d5860486
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ class SavedObjectOptions(TypedDict):
class AllOptionsDict(ExpandedOptionsDict):
prediction_count: int


class RecognizeOptionsDict(AllOptionsDict):
detect_faces: bool

```
| Option | Type | Notes |
| --------------------| ------ | ----------------------------------------- |
Expand All @@ -275,6 +279,10 @@ class AllOptionsDict(ExpandedOptionsDict):
| prediction_count | integer | maximum number of subject predictions per face. It returns the most similar subjects. Default value: 1 |
| face_plugins | string | comma-separated slugs of face plugins. If empty, no additional information is returned. [Learn more](https://github.com/exadel-inc/CompreFace/tree/master/docs/Face-services-and-plugins.md) |
| status | boolean | if true includes system information like execution_time and plugin_version fields. Default value is false |
| detect_faces | boolean | if true the parameter specifies whether to perform image detection or not. Default value is true |
| page | integer | page number of examples to return. Can be used for pagination. Default value is 0. |
| size | integer | faces on page (page size). Can be used for pagination. Default value is 20. |
| subject | string | what subject examples endpoint should return. If empty, return examples for all subjects.|

Example of face recognition with object:

Expand All @@ -284,7 +292,8 @@ recognition.recognize_image(image_path=image_path, options={
"det_prob_threshold": 0.8,
"prediction_count": 1,
"face_plugins": "calculator,age,gender,landmarks",
"status": "true"
"status": "true",
"detect_faces": True,
})
```

Expand All @@ -310,7 +319,7 @@ recognition.recognize_image(image_path, options)
| Argument | Type | Required | Notes |
| ------------------ | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| image_path | image | required | Image can pass from url, local path or bytes. Max size is 5Mb |
| options | object | optional | `AllOptionsDict` object can be used in this method. See more [here](#options-structure). |
| options | object | optional | `RecognizeOptionsDict` object can be used in this method. See more [here](#options-structure). |

Response:

Expand Down
4 changes: 2 additions & 2 deletions compreface/client/recognize_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import requests

from compreface.common.multipart_constructor import multipart_constructor
from compreface.common.typed_dict import AllOptionsDict, check_fields_by_name
from compreface.common.typed_dict import RecognizeOptionsDict, check_fields_by_name
from compreface.config.api_list import RECOGNIZE_API
from ..common import ClientRequest

Expand Down Expand Up @@ -44,7 +44,7 @@ def get(self):
:return: json from server.
"""

def post(self, image: str = "" or bytes, options: AllOptionsDict = {}):
def post(self, image: str = "" or bytes, options: RecognizeOptionsDict = {}):
url: str = self.url + "?"

# Validation loop and adding fields to the url.
Expand Down
6 changes: 5 additions & 1 deletion compreface/common/typed_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class AllOptionsDict(ExpandedOptionsDict):
prediction_count: int


class RecognizeOptionsDict(AllOptionsDict):
detect_faces: bool


"""
Checks fields with necessary rules.
:param name: key from dictionary.
Expand Down Expand Up @@ -78,7 +82,7 @@ def check_fields_by_name(name: str, value: Any):
and row.find("pose") == -1
):
raise IncorrectFieldException(
"face_plugins must be only contains calculator,age,gender,landmarks,mask. "
"face_plugins must be only contains calculator,age,gender,landmarks,mask,pose."
"Incorrect value {}".format(row)
)
if name == "page" or name == "size":
Expand Down
10 changes: 8 additions & 2 deletions compreface/service/recognition_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
permissions and limitations under the License.
"""

from compreface.common.typed_dict import AllOptionsDict, PredictionCountOptionsDict
from compreface.common.typed_dict import (
AllOptionsDict,
PredictionCountOptionsDict,
RecognizeOptionsDict,
)
from typing import List

from ..common import Service
Expand Down Expand Up @@ -51,7 +55,9 @@ def get_available_functions(self) -> List[str]:
"""
return self.available_services

def recognize_image(self, image_path: str, options: AllOptionsDict = {}) -> dict:
def recognize_image(
self, image_path: str, options: RecognizeOptionsDict = {}
) -> dict:
"""
Recognize faces from the uploaded image

Expand Down
4 changes: 2 additions & 2 deletions compreface/use_cases/recognize_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
permissions and limitations under the License.
"""

from compreface.common.typed_dict import AllOptionsDict
from compreface.common.typed_dict import RecognizeOptionsDict
from dataclasses import dataclass
from ..client import RecognizeFaceFromImageClient

Expand All @@ -30,6 +30,6 @@ def __init__(self, domain: str, port: str, api_key: str):
api_key=api_key, domain=domain, port=port
)

def execute(self, request: Request, options: AllOptionsDict = {}) -> dict:
def execute(self, request: Request, options: RecognizeOptionsDict = {}) -> dict:
result: dict = self.recognize_face_from_image.post(request.image_path, options)
return result
1 change: 1 addition & 0 deletions examples/recognize_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"prediction_count": 1,
"status": "true",
"face_plugins": "calculator",
"detect_faces": True,
},
)

Expand Down