Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

166 changes: 82 additions & 84 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion compreface/client/add_example_of_subject.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions compreface/client/delete_example_by_id.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from compreface.config.api_list import RECOGNIZE_CRUD_API
import requests

from ..common import ClientRequest
Expand All @@ -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

Expand All @@ -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()
12 changes: 4 additions & 8 deletions compreface/client/recognize_face_from_image.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'))}
Expand Down
12 changes: 4 additions & 8 deletions compreface/client/verify_face_from_image.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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'))}
Expand Down
22 changes: 21 additions & 1 deletion compreface/collections/face_collections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from compreface.use_cases.verify_face_from_image import VerifyFaceFromImage
from ..use_cases import (
AddExampleOfSubject,
ListOfAllSavedSubjects,
Expand All @@ -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,
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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)
Binary file removed compreface/common/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed compreface/common/__pycache__/client.cpython-38.pyc
Binary file not shown.
Binary file removed compreface/common/__pycache__/service.cpython-38.pyc
Binary file not shown.
Empty file added compreface/config/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions compreface/config/api_list.py
Original file line number Diff line number Diff line change
@@ -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'
Binary file removed compreface/core/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed compreface/core/__pycache__/model.cpython-38.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions compreface/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file removed compreface/service/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
37 changes: 3 additions & 34 deletions compreface/service/recognition_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from ..common import Service
from ..collections import FaceCollection
from ..use_cases import (
RecognizeFaceFromImage,
VerifyFaceFromImage
RecognizeFaceFromImage
)


Expand All @@ -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,
Expand All @@ -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)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 1 addition & 7 deletions compreface/use_cases/recognize_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
6 changes: 1 addition & 5 deletions compreface/use_cases/verify_face_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
16 changes: 8 additions & 8 deletions examples/add_example_of_a_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Binary file added examples/common/di_kaprio.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading