diff --git a/.gitignore b/.gitignore index e69de29..508c825 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,94 @@ +# Linux trash folder which might appear on any partition or disk +.Trash-* + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# PyBuilder +target/ + +# IPython +profile_default/ +ipython_config.py + +# Environments +# .env +.env/ +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# operating system-related files +# file properties cache/storage on macOS +*.DS_Store +# thumbnail cache on Windows +Thumbs.db + +# profiling data +.prof + + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + diff --git a/README.md b/README.md index eaa4ef3..93e1c5d 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,22 @@ CompreFace is free and open-source face recognition system from Exadel and this Python SDK helps you to use all functionalities of the system in your application without prior skills. ## Content + - [Installation](#installation) - [Recognition Service](#recognition) - [Usage](#usage) - ## Rest API description By using the created API key, the user can add an image as an example of a particular face, retrieve a list of saved images, recognize a face from the image uploaded to the Face Collection, and delete all examples of the face by the name. -## Installation +## Requirements -Run below command to install SDK in your environment. -```python - pip install compreface -``` +Before using our SDK make sure you have installed CompreFace and Python on your machine. + +1. [CompreFace](https://github.com/exadel-inc/CompreFace#getting-started-with-compreface) +2. [Python](https://nodejs.org/en/) (Version 3.7) +3. [requests-toolbelt] (pip install requests-toolbelt==0.9.1) ## Recognition Service @@ -25,15 +26,17 @@ Run below command to install SDK in your environment. This creates an example of the subject by saving images. You can add as many images as you want to train the system. -```python +```python FaceCollection.add(file, subject) ``` -| Element | Description | Type | Required | Notes | -| ------------------- | ----------- | ------ | -------- | ------------------------------------------------------------ | -| subject | param | string | required | is the name you assign to the image you save | -| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | + +| Element | Description | Type | Required | Notes | +| ------- | ----------- | ------ | -------- | -------------------------------------------------------------------------------------- | +| subject | param | string | required | is the name you assign to the image you save | +| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | Response body on success: + ``` { "image_id": "", @@ -41,29 +44,28 @@ Response body on success: } ``` -| Element | Type | Description | -| -------- | ------ | -------------------------- | -| image_id | UUID | UUID of uploaded image | +| Element | Type | Description | +| -------- | ------ | ------------------------ | +| image_id | UUID | UUID of uploaded image | | subject | string | of saved image | - - ### Recognize Faces from a Given Image Recognizes faces from the uploaded image. + ```python RecognitionService.recognize(file, limit, det_prob_threshold, prediction_count) ``` - -| Element | Description | Type | Required | Notes | -| ---------------- | ----------- | ------- | -------- | ------------------------------------------------------------ | -| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | -| limit | param | integer | optional | maximum number of faces with best similarity in result. Value of 0 represents no limit. Default value: 0 | -| det_prob_ threshold | param | string | optional | minimum required confidence that a recognized face is actually a face. Value is between 0.0 and 1.0. | -| prediction_count | param | integer | optional | maximum number of predictions per faces. Default value: 1 | +| Element | Description | Type | Required | Notes | +| ------------------- | ----------- | ------- | -------- | -------------------------------------------------------------------------------------------------------- | +| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | +| limit | param | integer | optional | maximum number of faces with best similarity in result. Value of 0 represents no limit. Default value: 0 | +| det*prob* threshold | param | string | optional | minimum required confidence that a recognized face is actually a face. Value is between 0.0 and 1.0. | +| prediction_count | param | integer | optional | maximum number of predictions per faces. Default value: 1 | Response body on success: + ``` { "result": [ @@ -78,7 +80,7 @@ Response body on success: "faces": [ { "similarity": , - "subject": + "subject": }, ... ] @@ -87,16 +89,14 @@ Response body on success: } ``` -| Element | Type | Description | -| ------------------------------ | ------- | ------------------------------------------------------------ | -| box | object | list of parameters of the bounding box for this face | -| probability | float | probability that a found face is actually a face | -| x_max, y_max, x_min, y_min | integer | coordinates of the frame containing the face | -| faces | list | list of similar faces with size of order by similarity | -| similarity | float | similarity that on that image predicted person | -| subject | string | name of the subject in Face Collection | - - +| Element | Type | Description | +| -------------------------- | ------- | ------------------------------------------------------------------------- | +| box | object | list of parameters of the bounding box for this face | +| probability | float | probability that a found face is actually a face | +| x_max, y_max, x_min, y_min | integer | coordinates of the frame containing the face | +| faces | list | list of similar faces with size of order by similarity | +| similarity | float | similarity that on that image predicted person | +| subject | string | name of the subject in Face Collection | ### List of All Saved Subjects @@ -120,25 +120,25 @@ Response body on success: } ``` -| Element | Type | Description | -| -------- | ------ | ------------------------------------------------------------ | -| image_id | UUID | UUID of the face | +| Element | Type | Description | +| -------- | ------ | ----------------------------------------------------------------- | +| image_id | UUID | UUID of the face | | subject | string | of the person, whose picture was saved for this api key | - ### Delete All Examples of the Subject by Name To delete all image examples of the : -```python +```python FaceCollection.delete_all(subject) ``` -| Element | Description | Type | Required | Notes | -| --------- | ----------- | ------ | -------- | ------------------------------------------------------------ | -| subject | param | string | optional | is the name you assign to the image you save. **Caution!** If this parameter is absent, all faces in Face Collection will be removed | +| Element | Description | Type | Required | Notes | +| ------- | ----------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| subject | param | string | optional | is the name you assign to the image you save. **Caution!** If this parameter is absent, all faces in Face Collection will be removed | Response body on success: + ``` [ { @@ -149,26 +149,25 @@ Response body on success: ] ``` -| Element | Type | Description | -| -------- | ------ | ------------------------------------------------------------ | -| image_id | UUID | UUID of the removed face | +| Element | Type | Description | +| -------- | ------ | ----------------------------------------------------------------- | +| image_id | UUID | UUID of the removed face | | subject | string | of the person, whose picture was saved for this api key | - - ### Delete an Example of the Subject by ID To delete an image by ID: -```python +```python FaceCollection.delete(image_id) ``` -| Element | Description | Type | Required | Notes | -| --------- | ----------- | ------ | -------- | ----------------------------------------- | -| image_id | variable | UUID | required | UUID of the removing face | +| Element | Description | Type | Required | Notes | +| -------- | ----------- | ---- | -------- | ------------------------- | +| image_id | variable | UUID | required | UUID of the removing face | Response body on success: + ``` { "image_id": , @@ -176,29 +175,28 @@ Response body on success: } ``` -| Element | Type | Description | -| -------- | ------ | ------------------------------------------------------------ | -| image_id | UUID | UUID of the removed face | +| Element | Type | Description | +| -------- | ------ | ----------------------------------------------------------------- | +| image_id | UUID | UUID of the removed face | | subject | string | of the person, whose picture was saved for this api key | - - ### Verify Faces from a Given Image To compare faces from the uploaded images with the face in saved image ID: -```python + +```python RecognitionService.verify(image_id, file, limit, det_prob_threshold) ``` - -| Element | Description | Type | Required | Notes | -| ---------------- | ----------- | ------- | -------- | ------------------------------------------------------------ | -| image_id | variable | UUID | required | UUID of the verifying face | -| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | -| limit | param | integer | optional | maximum number of faces with best similarity in result. Value of 0 represents no limit. Default value: 0 | -| det_prob_threshold | param | string | optional | minimum required confidence that a recognized face is actually a face. Value is between 0.0 and 1.0. | +| Element | Description | Type | Required | Notes | +| ------------------ | ----------- | ------- | -------- | -------------------------------------------------------------------------------------------------------- | +| image_id | variable | UUID | required | UUID of the verifying face | +| file | body | image | required | allowed image formats: jpeg, jpg, ico, png, bmp, gif, tif, tiff, webp. Max size is 5Mb | +| limit | param | integer | optional | maximum number of faces with best similarity in result. Value of 0 represents no limit. Default value: 0 | +| det_prob_threshold | param | string | optional | minimum required confidence that a recognized face is actually a face. Value is between 0.0 and 1.0. | Response body on success: + ``` { "result": [ @@ -217,19 +215,19 @@ Response body on success: } ``` -| Element | Type | Description | -| ------------------------------ | ------- | ------------------------------------------------------------ | -| box | object | list of parameters of the bounding box for this face | -| probability | float | probability that a found face is actually a face | -| x_max, y_max, x_min, y_min | integer | coordinates of the frame containing the face | -| similarity | float | similarity that on that image predicted person | -| subject | string | name of the subject in Face Collection | +| Element | Type | Description | +| -------------------------- | ------- | ---------------------------------------------------- | +| box | object | list of parameters of the bounding box for this face | +| probability | float | probability that a found face is actually a face | +| x_max, y_max, x_min, y_min | integer | coordinates of the frame containing the face | +| similarity | float | similarity that on that image predicted person | +| subject | string | name of the subject in Face Collection | ## Usage You only need to import and initialize CompreFace in order to use functionalities of services. Below given initial setup recognition service for your application. -```python +```python from compreface import CompreFace from compreface.service import RecognitionService @@ -247,7 +245,7 @@ recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) This creates an example of the subject by saving images. You can add as many images as you want to train the system. -```python +```python from compreface import CompreFace from compreface.service import RecognitionService from compreface.collections import FaceColliction @@ -269,10 +267,10 @@ subject: str = 'test' result = face_collection.add(image_path, subject) ``` - -### Example Recognize Faces from a Given Image +### Example Recognize Faces from a Given Image Recognizes faces from the uploaded image. + ```python from compreface import CompreFace from compreface.service import RecognitionService @@ -293,7 +291,7 @@ result = recognition.recognize(image_path) ``` -### Example List of All Saved Subjects +### Example List of All Saved Subjects To retrieve a list of subjects saved in a Face Collection: @@ -317,11 +315,11 @@ face_collection: FaceColliction = recognition.get_face_collection() result = face_collection.list() ``` -### Example Delete All Examples of the Subject by Name +### Example Delete All Examples of the Subject by Name To delete all image examples of the : -```python +```python from compreface import CompreFace from compreface.service import RecognitionService from compreface.collections import FaceColliction @@ -342,12 +340,11 @@ face_collection: FaceColliction = recognition.get_face_collection() result = recognition.delete_all(subject) ``` - -### Example Delete an Example of the Subject by ID +### Example Delete an Example of the Subject by ID To delete an image by ID: -```python +```python from compreface import CompreFace from compreface.service import RecognitionService from compreface.collections import FaceColliction @@ -369,10 +366,11 @@ result = face_collection.delete(image_id) ``` -### Example Verify Faces from a Given Image +### Example Verify Faces from a Given Image To compare faces from the uploaded images with the face in saved image ID: -```python + +```python from compreface import CompreFace from compreface.service import RecognitionService @@ -392,4 +390,4 @@ image_id: str = '3aff54a4-862b-48e5-a5e1-10056cc893da' result = verification.verify(image_path, image_id) ``` -All this examples you can find in repozitory inside "examples" folder. \ No newline at end of file +All this examples you can find in repozitory inside "examples" folder. diff --git a/compreface/client/add_example_of_subject.py b/compreface/client/add_example_of_subject.py index 2053514..114e6f5 100644 --- a/compreface/client/add_example_of_subject.py +++ b/compreface/client/add_example_of_subject.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from compreface.config.api_list import RECOGNIZE_CRUD_API import os import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -11,7 +12,7 @@ class AddExampleOfSubjectClient(ClientRequest): def __init__(self, api_key: str, domain: str, port: str): super().__init__() - self.client_url: str = '/api/v1/faces' + self.client_url: str = RECOGNIZE_CRUD_API self.api_key: str = api_key self.url: str = domain + ':' + port + self.client_url diff --git a/compreface/client/delete_example_by_id.py b/compreface/client/delete_example_by_id.py index 9a7883d..9991c47 100644 --- a/compreface/client/delete_example_by_id.py +++ b/compreface/client/delete_example_by_id.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from compreface.config.api_list import RECOGNIZE_CRUD_API import requests from ..common import ClientRequest @@ -9,7 +10,7 @@ class DeleteExampleByIdClient(ClientRequest): def __init__(self, api_key: str, domain: str, port: str): super().__init__() - self.client_url: str = '/api/v1/faces/' + self.client_url: str = RECOGNIZE_CRUD_API self.api_key: str = api_key self.url: str = domain + ':' + port + self.client_url @@ -23,6 +24,6 @@ def put(self): pass def delete(self, image_id: str = ''): - url: str = self.url + image_id + url: str = self.url + '/' + image_id result = requests.delete(url, headers={'x-api-key': self.api_key}) return result.json() diff --git a/compreface/client/recognize_face_from_image.py b/compreface/client/recognize_face_from_image.py index 499edf5..7f76d4d 100644 --- a/compreface/client/recognize_face_from_image.py +++ b/compreface/client/recognize_face_from_image.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from compreface.config.api_list import RECOGNIZE_API import os import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -11,20 +12,15 @@ class RecognizeFaceFromImageClient(ClientRequest): def __init__(self, api_key: str, domain: str, port: str): super().__init__() - self.client_url: str = '/api/v1/faces/recognize' + self.client_url: str = RECOGNIZE_API self.api_key: str = api_key self.url: str = domain + ':' + port + self.client_url def get(self): pass - def post(self, image_path: str = '', - limit: float = 0, - det_prob_threshold: float = 0, - prediction_count: int = 0): - url: str = self.url + '?limit=' + str(limit) + '&prediction_count=' + str(prediction_count) \ - + '&det_prob_threshold=' + \ - str(det_prob_threshold) + def post(self, image_path: str = ''): + url: str = self.url name_img: str = os.path.basename(image_path) m = MultipartEncoder( fields={'file': (name_img, open(image_path, 'rb'))} diff --git a/compreface/client/verify_face_from_image.py b/compreface/client/verify_face_from_image.py index 80b5f1d..8862ddd 100644 --- a/compreface/client/verify_face_from_image.py +++ b/compreface/client/verify_face_from_image.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from compreface.config.api_list import RECOGNIZE_CRUD_API import os import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -8,10 +9,9 @@ class VerifyFaceFromImageClient(ClientRequest): - def __init__(self, api_key: str, domain: str, port: str): super().__init__() - self.client_url: str = '/api/v1/faces/' + self.client_url: str = RECOGNIZE_CRUD_API self.api_key: str = api_key self.url: str = domain + ':' + port + self.client_url @@ -20,12 +20,8 @@ def get(self): def post(self, image_path: str = '', - image_id: str = '', - limit: float = 0, - det_prob_threshold: float = 0,): - url: str = self.url + image_id + '/verify' +'?limit=' + str(limit) + \ - '&det_prob_threshold=' + \ - str(det_prob_threshold) + image_id: str = ''): + url: str = self.url + '/' + image_id + '/verify' name_img: str = os.path.basename(image_path) m = MultipartEncoder( fields={'file': (name_img, open(image_path, 'rb'))} diff --git a/compreface/collections/face_collections.py b/compreface/collections/face_collections.py index af1fe1d..87af7df 100644 --- a/compreface/collections/face_collections.py +++ b/compreface/collections/face_collections.py @@ -1,4 +1,5 @@ +from compreface.use_cases.verify_face_from_image import VerifyFaceFromImage from ..use_cases import ( AddExampleOfSubject, ListOfAllSavedSubjects, @@ -8,10 +9,10 @@ class FaceCollection: - def __init__(self, api_key: str, domain: str, port: str): """Init service with define API Key""" self.available_services = [] + self.api_key = api_key self.add_example: AddExampleOfSubject = AddExampleOfSubject( domain=domain, port=port, @@ -32,6 +33,11 @@ def __init__(self, api_key: str, domain: str, port: str): port=port, api_key=api_key ) + self.verify_face_from_image: VerifyFaceFromImage = VerifyFaceFromImage( + domain=domain, + port=port, + api_key=api_key + ) def add(self, image_path: str, subject: str) -> dict: """ @@ -77,3 +83,17 @@ def delete(self, image_id: str) -> dict: image_id=image_id ) return self.delete_all_examples_by_id.execute(request) + + def verify(self, image_path: str, image_id: str) -> dict: + """ + Verify image + :param image_path: + :param image_id: + :return: + """ + request = VerifyFaceFromImage.Request( + api_key=self.api_key, + image_path=image_path, + image_id=image_id + ) + return self.verify_face_from_image.execute(request) diff --git a/compreface/common/__pycache__/__init__.cpython-38.pyc b/compreface/common/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 443f04c..0000000 Binary files a/compreface/common/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/compreface/common/__pycache__/client.cpython-38.pyc b/compreface/common/__pycache__/client.cpython-38.pyc deleted file mode 100644 index 414b2a5..0000000 Binary files a/compreface/common/__pycache__/client.cpython-38.pyc and /dev/null differ diff --git a/compreface/common/__pycache__/service.cpython-38.pyc b/compreface/common/__pycache__/service.cpython-38.pyc deleted file mode 100644 index 2ddc9d2..0000000 Binary files a/compreface/common/__pycache__/service.cpython-38.pyc and /dev/null differ diff --git a/compreface/config/__init__.py b/compreface/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/compreface/config/api_list.py b/compreface/config/api_list.py new file mode 100644 index 0000000..990c0e7 --- /dev/null +++ b/compreface/config/api_list.py @@ -0,0 +1,4 @@ +RECOGNITION_ROOT_API: str = '/api/v1/recognition' + +RECOGNIZE_API: str = RECOGNITION_ROOT_API + '/recognize' +RECOGNIZE_CRUD_API: str = RECOGNITION_ROOT_API + '/faces' diff --git a/compreface/core/__pycache__/__init__.cpython-38.pyc b/compreface/core/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 6c60fae..0000000 Binary files a/compreface/core/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/compreface/core/__pycache__/model.cpython-38.pyc b/compreface/core/__pycache__/model.cpython-38.pyc deleted file mode 100644 index 4831891..0000000 Binary files a/compreface/core/__pycache__/model.cpython-38.pyc and /dev/null differ diff --git a/compreface/core/model.py b/compreface/core/model.py index e7e0da9..7fc6b1e 100644 --- a/compreface/core/model.py +++ b/compreface/core/model.py @@ -54,8 +54,8 @@ def init_face_verification(self, api_key: str) -> VerificationService: :return: """ self.verification = VerificationService(api_key=api_key, - domain=self.domain, - port=self.port) + domain=self.domain, + port=self.port) return self.verification def init_face_detection(self, api_key: str) -> DetectionService: diff --git a/compreface/service/__pycache__/__init__.cpython-38.pyc b/compreface/service/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 595fd0e..0000000 Binary files a/compreface/service/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/compreface/service/__pycache__/detection_service.cpython-38.pyc b/compreface/service/__pycache__/detection_service.cpython-38.pyc deleted file mode 100644 index 2482807..0000000 Binary files a/compreface/service/__pycache__/detection_service.cpython-38.pyc and /dev/null differ diff --git a/compreface/service/__pycache__/recognition_service.cpython-38.pyc b/compreface/service/__pycache__/recognition_service.cpython-38.pyc deleted file mode 100644 index db8b23e..0000000 Binary files a/compreface/service/__pycache__/recognition_service.cpython-38.pyc and /dev/null differ diff --git a/compreface/service/__pycache__/verification_service.cpython-38.pyc b/compreface/service/__pycache__/verification_service.cpython-38.pyc deleted file mode 100644 index c7acd9a..0000000 Binary files a/compreface/service/__pycache__/verification_service.cpython-38.pyc and /dev/null differ diff --git a/compreface/service/recognition_service.py b/compreface/service/recognition_service.py index cd270e5..6c7b15f 100644 --- a/compreface/service/recognition_service.py +++ b/compreface/service/recognition_service.py @@ -5,8 +5,7 @@ from ..common import Service from ..collections import FaceCollection from ..use_cases import ( - RecognizeFaceFromImage, - VerifyFaceFromImage + RecognizeFaceFromImage ) @@ -17,11 +16,6 @@ def __init__(self, api_key: str, domain: str, port: str): """Init service with define API Key""" super().__init__(api_key) self.available_services = [] - self.verify_face_from_image: VerifyFaceFromImage = VerifyFaceFromImage( - domain=domain, - port=port, - api_key=api_key - ) self.recognize_face_from_images: RecognizeFaceFromImage = RecognizeFaceFromImage( domain=domain, port=port, @@ -40,40 +34,15 @@ def get_available_functions(self) -> List[str]: """ return self.available_services - def verify(self, image_path: str, image_id: str, limit: int = 0, det_prob_threshold: float = 0.8) -> dict: - """ - Verify image - :param image_path: - :param image_id: - :param limit: - :param det_prob_threshold: - :return: - """ - request = VerifyFaceFromImage.Request( - api_key=self.api_key, - image_path=image_path, - image_id=image_id, - limit=limit, - det_prob_threshold=det_prob_threshold - ) - return self.verify_face_from_image.execute(request) - - def recognize(self, image_path: str, limit: float = 0, det_prob_threshold: float = 0.8, - prediction_count: int = 1) -> dict: + def recognize(self, image_path: str) -> dict: """ Recognize image :param image_path: - :param limit: - :param det_prob_threshold: - :param prediction_count: :return: """ request = RecognizeFaceFromImage.Request( api_key=self.api_key, - image_path=image_path, - limit=limit, - det_prob_threshold=det_prob_threshold, - prediction_count=prediction_count + image_path=image_path ) return self.recognize_face_from_images.execute(request) diff --git a/compreface/use_cases/__pycache__/__init__.cpython-38.pyc b/compreface/use_cases/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 784b11f..0000000 Binary files a/compreface/use_cases/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/add_example_of_subject.cpython-38.pyc b/compreface/use_cases/__pycache__/add_example_of_subject.cpython-38.pyc deleted file mode 100644 index 62be34d..0000000 Binary files a/compreface/use_cases/__pycache__/add_example_of_subject.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/delete_all_examples_of_subject_by_name.cpython-38.pyc b/compreface/use_cases/__pycache__/delete_all_examples_of_subject_by_name.cpython-38.pyc deleted file mode 100644 index 6a95d97..0000000 Binary files a/compreface/use_cases/__pycache__/delete_all_examples_of_subject_by_name.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/delete_example_by_id.cpython-38.pyc b/compreface/use_cases/__pycache__/delete_example_by_id.cpython-38.pyc deleted file mode 100644 index c711502..0000000 Binary files a/compreface/use_cases/__pycache__/delete_example_by_id.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/list_of_all_saved_subjects.cpython-38.pyc b/compreface/use_cases/__pycache__/list_of_all_saved_subjects.cpython-38.pyc deleted file mode 100644 index 0ff9ba1..0000000 Binary files a/compreface/use_cases/__pycache__/list_of_all_saved_subjects.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/recognize_face_from_image.cpython-38.pyc b/compreface/use_cases/__pycache__/recognize_face_from_image.cpython-38.pyc deleted file mode 100644 index 61a5215..0000000 Binary files a/compreface/use_cases/__pycache__/recognize_face_from_image.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/__pycache__/verify_face_from_image.cpython-38.pyc b/compreface/use_cases/__pycache__/verify_face_from_image.cpython-38.pyc deleted file mode 100644 index 0841e1c..0000000 Binary files a/compreface/use_cases/__pycache__/verify_face_from_image.cpython-38.pyc and /dev/null differ diff --git a/compreface/use_cases/recognize_face_from_image.py b/compreface/use_cases/recognize_face_from_image.py index 5f2d89b..2015175 100644 --- a/compreface/use_cases/recognize_face_from_image.py +++ b/compreface/use_cases/recognize_face_from_image.py @@ -10,9 +10,6 @@ class RecognizeFaceFromImage: class Request: api_key: str image_path: str - limit: float = 0 - det_prob_threshold: float = 0.8 - prediction_count: int = 1 def __init__(self, domain: str, port: str, api_key: str): self.recognize_face_from_image = RecognizeFaceFromImageClient( @@ -22,8 +19,5 @@ def __init__(self, domain: str, port: str, api_key: str): ) def execute(self, request: Request) -> dict: - result: dict = self.recognize_face_from_image.post(request.image_path, - request.limit, - request.det_prob_threshold, - request.prediction_count) + result: dict = self.recognize_face_from_image.post(request.image_path) return result diff --git a/compreface/use_cases/verify_face_from_image.py b/compreface/use_cases/verify_face_from_image.py index 0896deb..9b2679d 100644 --- a/compreface/use_cases/verify_face_from_image.py +++ b/compreface/use_cases/verify_face_from_image.py @@ -11,8 +11,6 @@ class Request: api_key: str image_path: str image_id: str - limit: float = 0 - det_prob_threshold: float = 0.8 def __init__(self, domain: str, port: str, api_key: str): self.verify_face_from_image = VerifyFaceFromImageClient( @@ -23,7 +21,5 @@ def __init__(self, domain: str, port: str, api_key: str): def execute(self, request: Request): result: dict = self.verify_face_from_image.post(request.image_path, - request.image_id, - request.limit, - request.det_prob_threshold) + request.image_id) return result diff --git a/examples/add_example_of_a_subject.py b/examples/add_example_of_a_subject.py index 1d30cfd..b016644 100644 --- a/examples/add_example_of_a_subject.py +++ b/examples/add_example_of_a_subject.py @@ -2,20 +2,20 @@ from compreface import CompreFace from compreface.service import RecognitionService -from compreface.collections import FaceColliction - +from compreface.collections import FaceCollection DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' - +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) + +face_collection: FaceCollection = recognition.get_face_collection() -face_collection: FaceColliction = recognition.get_face_collection() +image_path: str = 'examples/common/di_kaprio.jpg' +subject: str = 'Leonardo Wilhelm DiCaprio' -image_path: str = '/home/aliubymov/A-OZSXlgs3c.jpg' -subject: str = 'test' print(face_collection.add(image_path, subject)) diff --git a/examples/common/di_kaprio.jpg b/examples/common/di_kaprio.jpg new file mode 100644 index 0000000..f957e00 Binary files /dev/null and b/examples/common/di_kaprio.jpg differ diff --git a/examples/delete_all_examples_of_subject.py b/examples/delete_all_examples_of_subject.py index a6b7929..481d240 100644 --- a/examples/delete_all_examples_of_subject.py +++ b/examples/delete_all_examples_of_subject.py @@ -2,19 +2,19 @@ from compreface import CompreFace from compreface.service import RecognitionService -from compreface.collections import FaceColliction - +from compreface.collections import FaceCollection DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) -subject: str = 'test' +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) +subject: str = 'Leonardo Wilhelm DiCaprio' -face_collection: FaceColliction = recognition.get_face_collection() +face_collection: FaceCollection = recognition.get_face_collection() -print(recognition.delete_all(subject)) +print(face_collection.delete_all(subject)) diff --git a/examples/delete_example_by_id.py b/examples/delete_example_by_id.py index 418190e..3c9171e 100644 --- a/examples/delete_example_by_id.py +++ b/examples/delete_example_by_id.py @@ -2,19 +2,24 @@ from compreface import CompreFace from compreface.service import RecognitionService -from compreface.collections import FaceColliction - +from compreface.collections import FaceCollection DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) -image_id: str = '3aff54a4-862b-48e5-a5e1-10056cc893da' +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) + +face_collection: FaceCollection = recognition.get_face_collection() -face_collection: FaceColliction = recognition.get_face_collection() +faces: list = face_collection.list().get('faces') -print(face_collection.delete(image_id)) +if(len(faces) != 0): + last_face: dict = faces[len(faces) - 1] + print(face_collection.delete(last_face.get('image_id'))) +else: + print('No subject found') diff --git a/examples/get_list_of_all_subjects.py b/examples/get_list_of_all_subjects.py index 0d3a581..2f715d3 100644 --- a/examples/get_list_of_all_subjects.py +++ b/examples/get_list_of_all_subjects.py @@ -2,18 +2,18 @@ from compreface import CompreFace from compreface.service import RecognitionService -from compreface.collections import FaceColliction - +from compreface.collections import FaceCollection DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) -face_collection: FaceColliction = recognition.get_face_collection() +face_collection: FaceCollection = recognition.get_face_collection() print(face_collection.list()) diff --git a/examples/recognize_face_from_image.py b/examples/recognize_face_from_image.py index 319d1cf..05a83ac 100644 --- a/examples/recognize_face_from_image.py +++ b/examples/recognize_face_from_image.py @@ -3,16 +3,16 @@ from compreface import CompreFace from compreface.service import RecognitionService - DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -recognition: RecognitionService = compre_face.init_face_recognition(API_KEY) +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) -image_path: str = '/home/aliubymov/A-OZSXlgs3c.jpg' +image_path: str = 'examples/common/di_kaprio.jpg' print(recognition.recognize(image_path)) diff --git a/examples/verify_face_from_image.py b/examples/verify_face_from_image.py index de30fb4..02cb58f 100644 --- a/examples/verify_face_from_image.py +++ b/examples/verify_face_from_image.py @@ -1,19 +1,25 @@ # -*- coding: utf-8 -*- +from compreface.collections.face_collections import FaceCollection from compreface import CompreFace from compreface.service import RecognitionService - DOMAIN: str = 'http://localhost' PORT: str = '8000' -API_KEY: str = '7dacfc8e-1bb1-4fcf-a9b1-76e4d9d89855' - +RECOGNITION_API_KEY: str = '9916f5d1-216f-4049-9e06-51c140bfa898' compre_face: CompreFace = CompreFace(DOMAIN, PORT) -verification: RecognitionService = compre_face.init_face_recognition(API_KEY) +recognition: RecognitionService = compre_face.init_face_recognition( + RECOGNITION_API_KEY) + +image_path: str = 'examples/common/di_kaprio.jpg' + +face_collection: FaceCollection = recognition.get_face_collection() + +face: dict = next(item for item in face_collection.list().get('faces') if item['subject'] == + 'Leonardo Wilhelm DiCaprio') -image_path: str = '/home/aliubymov/A-OZSXlgs3c.jpg' -image_id: str = '3aff54a4-862b-48e5-a5e1-10056cc893da' +image_id = face.get('image_id') -print(verification.verify(image_path, image_id)) +print(face_collection.verify(image_path, image_id))