From f4a4c4848bf58fdcdd07357a503ecdc84de01623 Mon Sep 17 00:00:00 2001 From: Devasy Patel <110348311+Devasy23@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:08:45 +0530 Subject: [PATCH] Updated create_new_faceEntry function to handle multiple images --- API/route.py | 14 +++++++++----- API/utils.py | 4 ++-- CHANGELOG.md | 17 +++++++++++++++-- test.ipynb | 39 +++++++++++++++++++++++---------------- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/API/route.py b/API/route.py index 107d98d..f26f56b 100644 --- a/API/route.py +++ b/API/route.py @@ -4,9 +4,8 @@ import os from datetime import datetime from io import BytesIO - -from API.utils import init_logging_config from typing import List + from bson import ObjectId from deepface import DeepFace from fastapi import APIRouter, Form, HTTPException, Response @@ -16,6 +15,7 @@ from pymongo import MongoClient from API.database import Database +from API.utils import init_logging_config init_logging_config() @@ -64,11 +64,12 @@ async def create_new_faceEntry(Employee: Employee): Department = Employee.Department encoded_images = Employee.Images time = datetime.now() - + embeddings = [] for encoded_image in encoded_images: img_recovered = base64.b64decode(encoded_image) # decode base64string pil_image = Image.open(BytesIO(img_recovered)) + logging.info(f"Image opened {Name}") image_filename = f"{Name}.png" pil_image.save(image_filename) pil_image.save(f"Images\dbImages\{Name}.jpg") @@ -76,12 +77,15 @@ async def create_new_faceEntry(Employee: Employee): image_filename, detector_backend="mtcnn", enforce_detection=False ) plt.imsave(f"Images/Faces/{Name}.jpg", face_image_data[0]["face"]) + logging.info(f"Face saved {Name}") embedding = DeepFace.represent( image_filename, model_name="Facenet", detector_backend="mtcnn" ) embeddings.append(embedding) + logging.info(f"Embedding created Embeddings for {Name}") os.remove(image_filename) - + + logging.debug(f"About to insert Embeddings: {embeddings}") # Store the data in the database client.insert_one( collection, @@ -95,7 +99,7 @@ async def create_new_faceEntry(Employee: Employee): "Images": encoded_images, }, ) - + return {"message": "Face entry created successfully"} diff --git a/API/utils.py b/API/utils.py index 226c873..1003f38 100644 --- a/API/utils.py +++ b/API/utils.py @@ -35,7 +35,7 @@ def format(self, record): stderr_handler.setFormatter(CustomFormatter()) logger.addHandler(stderr_handler) - file_handler = logging.FileHandler("app.log", mode="w") + file_handler = logging.FileHandler("app.log", mode="w") file_handler.setLevel(logging.DEBUG) file_handler.setFormatter(CustomFormatter(True)) - logger.addHandler(file_handler) \ No newline at end of file + logger.addHandler(file_handler) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f99b4..a20115a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ -## [Unreleased] +## [0.0.1] - 2024-03-08 - 2:30 ### Added - Implemented all test cases in `test_face_cycle` -- Implemented mock test cases for `test_face_cycle` to work on online runners \ No newline at end of file +- Implemented mock test cases for `test_face_cycle` to work on online runners + +## [0.1.0] - 2024-03-08 - 17:10 + +### Added +- Updated `create_new_faceEntry` function in [`route.py`](route/route.py) to handle multiple images for each employee. +- Updated `test_face_lifecycle` function in [`test_face_cycle.py`](testing/test_face_cycle.py) to handle multiple images for each employee in the test data. + +### Changed +- Modified the `Employee` and `UpdateEmployee` models in [`route.py`](route/route.py) to include a list of images instead of a single image. +- Adjusted the mock data and assertions in [`test_face_cycle.py`](testing/test_face_cycle.py) to handle multiple images for each employee. + +### Fixed +- Resolved an issue where the `create_new_faceEntry` function in [`route.py`](route/route.py) was not correctly processing multiple images for each employee. \ No newline at end of file diff --git a/test.ipynb b/test.ipynb index 556d392..622d675 100644 --- a/test.ipynb +++ b/test.ipynb @@ -631,13 +631,16 @@ "outputs": [], "source": [ "url = \"http://127.0.0.1:8000/create_new_faceEntry\"\n", - "resp = requests.post(url=url, json={\n", - " \"EmployeeCode\": 134,\n", - " \"Name\": \"Name\",\n", - " \"gender\": \"gender\",\n", - " \"Department\": \"Department\",\n", - " \"Image\": \"your_image\",\n", - "})" + "resp = requests.post(\n", + " url=url,\n", + " json={\n", + " \"EmployeeCode\": 134,\n", + " \"Name\": \"Name\",\n", + " \"gender\": \"gender\",\n", + " \"Department\": \"Department\",\n", + " \"Image\": \"your_image\",\n", + " },\n", + ")" ] }, { @@ -676,16 +679,20 @@ ], "source": [ "from API.database import Database\n", + "\n", "EmployeeCode = 1\n", "client = Database()\n", - "client.find_one(\"faceEntries\", filter={\"EmployeeCode\": EmployeeCode},\n", - " projection={\n", - " \"Name\": True,\n", - " \"gender\": True,\n", - " \"Department\": True,\n", - " \"Image\": True,\n", - " \"_id\": False,\n", - " })" + "client.find_one(\n", + " \"faceEntries\",\n", + " filter={\"EmployeeCode\": EmployeeCode},\n", + " projection={\n", + " \"Name\": True,\n", + " \"gender\": True,\n", + " \"Department\": True,\n", + " \"Image\": True,\n", + " \"_id\": False,\n", + " },\n", + ")" ] } ], @@ -705,7 +712,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.11.8" } }, "nbformat": 4,