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"])