From 1416b83b4e5063d61a70caa5ea58452d6dfd6bef Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 11 Sep 2023 17:21:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E7=94=A8vggface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...me_facenet512_data_employee_facenet_data.py | 18 ++++++++++++++++++ apps/hrm/models.py | 2 +- apps/hrm/services.py | 8 ++++---- apps/hrm/tasks.py | 4 ++-- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 apps/hrm/migrations/0013_rename_facenet512_data_employee_facenet_data.py diff --git a/apps/hrm/migrations/0013_rename_facenet512_data_employee_facenet_data.py b/apps/hrm/migrations/0013_rename_facenet512_data_employee_facenet_data.py new file mode 100644 index 00000000..518245c0 --- /dev/null +++ b/apps/hrm/migrations/0013_rename_facenet512_data_employee_facenet_data.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2023-09-11 09:17 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('hrm', '0012_employee_facenet512_data'), + ] + + operations = [ + migrations.RenameField( + model_name='employee', + old_name='facenet512_data', + new_name='facenet_data', + ), + ] diff --git a/apps/hrm/models.py b/apps/hrm/models.py index 6bab5c49..d4ed97a5 100755 --- a/apps/hrm/models.py +++ b/apps/hrm/models.py @@ -44,7 +44,7 @@ class Employee(CommonBModel): not_work_remark = models.CharField('当前未打卡说明', null=True, blank=True, max_length=200) third_info = models.JSONField('三方信息', default=dict, null=False, blank=True) # 主要是定位卡信息 post = models.ForeignKey(Post, verbose_name='所属岗位', on_delete=models.SET_NULL, null=True, blank=True) - facenet512_data = models.JSONField('人脸数据', null=True, blank=True) + facenet_data = models.JSONField('人脸数据', null=True, blank=True) class Meta: verbose_name = '员工补充信息' verbose_name_plural = verbose_name diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 26e22fda..784ffbaa 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -410,13 +410,13 @@ class HrmService: 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') + 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() - dfs = face_find(img_path=img_path, global_df=face_df) - # dfs = DeepFace.find(img_path=img_path, db_path=db_path) + # dfs = face_find(img_path=img_path, global_df=face_df) + dfs = DeepFace.find(img_path=img_path, db_path=db_path) df = dfs[0] if not df.empty: matched = df.iloc[0].identity @@ -428,7 +428,7 @@ class HrmService: def get_facedata_from_img(cls, img_path): try: from deepface import DeepFace - embedding_objs = DeepFace.represent(img_path=img_path, model_name='Facenet512') + embedding_objs = DeepFace.represent(img_path=img_path) return embedding_objs[0]["embedding"], '' except Exception as e: return None, '人脸数据获取失败请重新上传图片' \ No newline at end of file diff --git a/apps/hrm/tasks.py b/apps/hrm/tasks.py index 722d13e6..d148d37c 100755 --- a/apps/hrm/tasks.py +++ b/apps/hrm/tasks.py @@ -130,7 +130,7 @@ def delete_face_pkl(epId): def update_global_face_pd(): import pandas as pd facedata = Employee.objects.filter(facenet512_data__isnull=False, - user__is_active=True).values_list('id', 'facenet512_data') - face_df = pd.DataFrame(list(facedata), columns=["identity", "Facenet512_representation"]) + 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) return face_df \ No newline at end of file