From 6771a499c6a0e94c46615807fac6360f6198b8b7 Mon Sep 17 00:00:00 2001 From: Markham Lee Date: Tue, 5 Mar 2024 21:06:37 -0800 Subject: [PATCH] Small refactoring: more logging messages, updated headers --- api/.dockerignore | 1 + api/logging_util.py | 2 -- api/photo_inferencing.py | 7 +++++++ api/requirements.txt | 2 -- api/score_service.py | 5 +++++ api/server.py | 5 +++++ 6 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 api/.dockerignore diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 0000000..5890b09 --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1 @@ +test.py diff --git a/api/logging_util.py b/api/logging_util.py index abcb927..57f1012 100644 --- a/api/logging_util.py +++ b/api/logging_util.py @@ -1,10 +1,8 @@ # Logging script - writes all data to stdout so that it can be picked up # by container orchestration tools like Kubernetes - import logging from sys import stdout - # set up/configure logging via stdout so it can be picked up by K8s logger = logging.getLogger('telemetry_logger') logger.setLevel(logging.DEBUG) diff --git a/api/photo_inferencing.py b/api/photo_inferencing.py index f0d155f..3e6a2f9 100644 --- a/api/photo_inferencing.py +++ b/api/photo_inferencing.py @@ -1,3 +1,6 @@ +# (C) Markham 2022 - 2024 +# Facial-Recognition-Facenet-Pytorch +# Flask based API wrapper around the Facenet-PyTorch facial recognition library import torch import warnings from facenet_pytorch import MTCNN, InceptionResnetV1 @@ -37,6 +40,8 @@ def identity_verify(self, reference: object, sample: object) -> object: embeddings_reference = self.resnet(reference_cropped.unsqueeze(0)) embeddings_sample = self.resnet(sample_cropped.unsqueeze(0)) + logger.debug('Embeddings generated for photo pair') + return embeddings_reference, embeddings_sample def cached_reference(self, sample: object) -> object: @@ -50,4 +55,6 @@ def cached_reference(self, sample: object) -> object: embeddings_sample = self.resnet(sample_cropped.unsqueeze(0)).\ detach().cpu() + logger.debug('Embeddings generated for single photo/cached tensor workflow') # noqa: E501 + return embeddings_sample diff --git a/api/requirements.txt b/api/requirements.txt index b982ee3..89d9a0e 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -7,8 +7,6 @@ opencv-python==4.8.0.74 pandas==2.0.3 pillow>=10.0.1 requests==2.31.0 -scipy==1.11.1 torch==2.0.1 -torchaudio==2.0.2 torchvision==0.15.2 Werkzeug==3.0.1 \ No newline at end of file diff --git a/api/score_service.py b/api/score_service.py index 8faf1f7..c8f5958 100644 --- a/api/score_service.py +++ b/api/score_service.py @@ -1,3 +1,8 @@ +# (C) Markham 2022 - 2024 +# Facial-Recognition-Facenet-Pytorch +# Flask based API wrapper around the Facenet-PyTorch facial recognition library +# This script calculates cosine distance and does the comparison to the +# provided threshold. import torch import torch.nn.functional as F from logging_util import logger diff --git a/api/server.py b/api/server.py index 75dd607..2e9f9c3 100644 --- a/api/server.py +++ b/api/server.py @@ -1,3 +1,8 @@ +# (C) Markham 2022 - 2024 +# Facial-Recognition-Facenet-Pytorch +# Flask based API wrapper around the Facenet-PyTorch facial recognition library +# This script is specifically for the API, receives requests, communicates back +# to the client, etc. import flask import json import torch