Skip to content

Commit

Permalink
Small refactoring: more logging messages, updated headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkhamLee committed Mar 6, 2024
1 parent 02d4c1e commit 6771a49
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.py
2 changes: 0 additions & 2 deletions api/logging_util.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 7 additions & 0 deletions api/photo_inferencing.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
2 changes: 0 additions & 2 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions api/score_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/server.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6771a49

Please sign in to comment.