From e27f6631a00054635851b27395fd478c5eadb98c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 11 Sep 2023 15:52:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E7=B1=BB=E4=BB=A3=E6=9B=BF?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/services.py | 10 ++++++++-- apps/hrm/tasks.py | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 8b1838a0..b291ab20 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -16,10 +16,16 @@ from apps.third.models import TDevice from apps.third.tapis import dhapis from apps.utils.tools import rannum, ranstr from apps.utils.face import face_find +from apps.utils.tools import singleton myLogger = logging.getLogger('log') -global_face_df = None #全局人脸库dataframe +@singleton +class FaceDb(): + def __init__(self, face_df) -> None: + self.face_df = face_df + +facedb = FaceDb(None) class HrmService: @@ -412,7 +418,7 @@ class HrmService: f.write(base64_data) # db_path = os.path.join(settings.BASE_DIR, 'media/face') # cache_face_db = cache - dfs = face_find(img_path=img_path, global_df=global_face_df, model_name='Facenet512') + dfs = face_find(img_path=img_path, global_df=facedb.face_df, model_name='Facenet512') df = dfs[0] if not df.empty: matched = df.iloc[0].identity diff --git a/apps/hrm/tasks.py b/apps/hrm/tasks.py index 542ac4ba..abb74c00 100755 --- a/apps/hrm/tasks.py +++ b/apps/hrm/tasks.py @@ -8,7 +8,7 @@ from dateutil import tz from django.core.cache import cache from apps.hrm.models import Employee -from apps.hrm.services import HrmService, global_face_df +from apps.hrm.services import HrmService, facedb from apps.third.dahua import dhClient from apps.third.tapis import dhapis from apps.utils.tasks import CustomTask @@ -132,5 +132,4 @@ def update_global_face_pd(): facedata = Employee.objects.filter(facenet512_data__isnull=False, user__is_active=True).values_list('id', 'facenet512_data') cache.set('global_face_data', facedata, timeout=None) - global global_face_df - global_face_df = pd.DataFrame(list(facedata), columns=["identity", "Facenet512_representation"]) + facedb.face_df = pd.DataFrame(list(facedata), columns=["identity", "Facenet512_representation"])