diff --git a/apps/hrm/apps.py b/apps/hrm/apps.py index 4fd510b3..d7a1c677 100755 --- a/apps/hrm/apps.py +++ b/apps/hrm/apps.py @@ -7,8 +7,8 @@ class HrmConfig(AppConfig): verbose_name = '人力资源管理' def ready(self): - if cache.get('update_global_face_pd_task', True): - from apps.hrm.tasks import update_global_face_pd - update_global_face_pd.delay() - cache.set('update_global_face_pd_task', False, timeout=30) + # if cache.get('update_global_face_pd_task', True): + # from apps.hrm.tasks import update_global_face_pd + # update_global_face_pd.delay() + # cache.set('update_global_face_pd_task', False, timeout=30) return super().ready() diff --git a/apps/hrm/serializers.py b/apps/hrm/serializers.py index 8c5c2f67..0b9534bb 100755 --- a/apps/hrm/serializers.py +++ b/apps/hrm/serializers.py @@ -77,8 +77,8 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer): instance.save() else: raise ParseError(msg) - from apps.hrm.tasks import update_global_face_pd - update_global_face_pd.delay() + from apps.hrm.tasks import update_global_face + update_global_face.delay() if instance.user and instance != old_name: instance.user.name = instance.name instance.user.save() diff --git a/apps/hrm/services.py b/apps/hrm/services.py index a361b792..78569a92 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -405,18 +405,18 @@ class HrmService: @classmethod def face_find_from_base64(cls, base64_data): - from deepface import DeepFace + # from deepface import DeepFace img_name = str(uuid.uuid4()) img_path = settings.BASE_DIR +'/temp/face_' + img_name +'.jpg' with open(img_path, 'wb') as f: f.write(base64_data) # db_path = os.path.join(settings.BASE_DIR, 'media/face') - face_df = cache.get('global_face_df', None) - if face_df is None: - from apps.hrm.tasks import update_global_face_pd - face_df = update_global_face_pd() - face_df = cache.get('global_face_df') - dfs = face_find(img_path=img_path, global_df=face_df) + global_face = cache.get('global_face', None) + if global_face is None: + from apps.hrm.tasks import update_global_face + global_face = update_global_face() + global_face = cache.get('global_face') + dfs = face_find(img_path=img_path, global_face=global_face) # dfs = DeepFace.find(img_path=img_path, db_path=db_path) df = dfs[0] if not df.empty: diff --git a/apps/hrm/tasks.py b/apps/hrm/tasks.py index 9db26380..279310f5 100755 --- a/apps/hrm/tasks.py +++ b/apps/hrm/tasks.py @@ -127,9 +127,7 @@ def delete_face_pkl(epId): @shared_task(base=CustomTask) -def update_global_face_pd(): - import pandas as pd +def update_global_face(): facedata = Employee.objects.filter(face_data__isnull=False, user__is_active=True).values_list('id', 'face_data') - face_df = pd.DataFrame(list(facedata), columns=["identity", "VGG-Face_representation"]) - cache.set('global_face_df', face_df, timeout=None) \ No newline at end of file + cache.set('global_face', list(facedata), timeout=None) \ No newline at end of file diff --git a/apps/utils/face.py b/apps/utils/face.py index 38bd44fc..01615a8c 100644 --- a/apps/utils/face.py +++ b/apps/utils/face.py @@ -5,7 +5,7 @@ import time def face_find( img_path, - global_df, + global_face: list, model_name="VGG-Face", distance_metric="cosine", enforce_detection=True, @@ -17,7 +17,7 @@ def face_find( tic = time.time() target_size = functions.find_target_size(model_name=model_name) # now, we got representations for facial database - df = global_df + df = pd.DataFrame(global_face, columns=["identity", f"{model_name}_representation"]) # img path might have more than once face target_objs = functions.extract_faces(