fix: 用类代替全局变量
This commit is contained in:
parent
e97879811f
commit
e27f6631a0
|
@ -16,10 +16,16 @@ from apps.third.models import TDevice
|
||||||
from apps.third.tapis import dhapis
|
from apps.third.tapis import dhapis
|
||||||
from apps.utils.tools import rannum, ranstr
|
from apps.utils.tools import rannum, ranstr
|
||||||
from apps.utils.face import face_find
|
from apps.utils.face import face_find
|
||||||
|
from apps.utils.tools import singleton
|
||||||
|
|
||||||
myLogger = logging.getLogger('log')
|
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:
|
class HrmService:
|
||||||
|
|
||||||
|
@ -412,7 +418,7 @@ class HrmService:
|
||||||
f.write(base64_data)
|
f.write(base64_data)
|
||||||
# db_path = os.path.join(settings.BASE_DIR, 'media/face')
|
# db_path = os.path.join(settings.BASE_DIR, 'media/face')
|
||||||
# cache_face_db = cache
|
# 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]
|
df = dfs[0]
|
||||||
if not df.empty:
|
if not df.empty:
|
||||||
matched = df.iloc[0].identity
|
matched = df.iloc[0].identity
|
||||||
|
|
|
@ -8,7 +8,7 @@ from dateutil import tz
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
from apps.hrm.models import Employee
|
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.dahua import dhClient
|
||||||
from apps.third.tapis import dhapis
|
from apps.third.tapis import dhapis
|
||||||
from apps.utils.tasks import CustomTask
|
from apps.utils.tasks import CustomTask
|
||||||
|
@ -132,5 +132,4 @@ def update_global_face_pd():
|
||||||
facedata = Employee.objects.filter(facenet512_data__isnull=False,
|
facedata = Employee.objects.filter(facenet512_data__isnull=False,
|
||||||
user__is_active=True).values_list('id', 'facenet512_data')
|
user__is_active=True).values_list('id', 'facenet512_data')
|
||||||
cache.set('global_face_data', facedata, timeout=None)
|
cache.set('global_face_data', facedata, timeout=None)
|
||||||
global global_face_df
|
facedb.face_df = pd.DataFrame(list(facedata), columns=["identity", "Facenet512_representation"])
|
||||||
global_face_df = pd.DataFrame(list(facedata), columns=["identity", "Facenet512_representation"])
|
|
||||||
|
|
Loading…
Reference in New Issue