From 4263d18fec5a8f29d312becb39b19c91b0b57ee8 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Thu, 5 Jan 2023 22:22:55 -0800 Subject: [PATCH] Recogition is off; face landmarks are not great. Maybe switch to other than retinaface and arcface Signed-off-by: James Ketrenos --- server/cluster.py | 54 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/server/cluster.py b/server/cluster.py index 0423672..9db31e9 100644 --- a/server/cluster.py +++ b/server/cluster.py @@ -126,26 +126,28 @@ def l2_normalize(x): base = '/pictures/' conn = create_connection('../db/photos.db') faces = {} -identities = {} +identities = [] with conn: cur = conn.cursor() res = cur.execute(''' - SELECT faces.id,facedescriptors.descriptors + SELECT faces.id,facedescriptors.descriptors,faces.faceConfidence,faces.photoId FROM faces JOIN facedescriptors ON (faces.descriptorId=facedescriptors.id) WHERE faces.identityId IS null ''') for row in res.fetchall(): - id, descriptors = row + id, descriptors, confidence, photoId = row if id in faces: face = faces[id] else: face = { - 'id': id, + 'id': id, 'scanned': False } faces[id] = face + face['confidence'] = confidence + face['photoId'] = photoId face['descriptors'] = np.frombuffer(descriptors) for key1 in faces: @@ -157,6 +159,8 @@ with conn: if key1 == key2: continue face2 = faces[key2] + if face2['scanned']: + continue face = { 'between': (face1['id'], face2['id']) } @@ -173,15 +177,49 @@ with conn: l2_normalize(face1['descriptors']), l2_normalize(face2['descriptors']) ) + face['scoring'] = 0 - if face['distanceCosine'] >= 0.68: + if face['distanceCosine'] < 0.65: face['scoring'] += 1 - if face['distanceEuclidian'] >= 4.15: + if face['distanceEuclidian'] < 4.00: face['scoring'] += 1 - if face['distanceEuclidianL2'] >= 1.13: + if face['distanceEuclidianL2'] < 1.055: face['scoring'] += 1 if face['scoring'] == 3: # Same face! - print(face) + if ('identity' in face1) and ('identity' in face2): + if face1['identity'] != face2['identity']: + # print(f'Identity mismatch between {key1}({face1["confidence"]}) and {key2}({face2["confidence"]})') + continue + elif 'identity' in face1: + face2['identity'] = face1['identity'] + face1['identity']['members'].append(face) + elif 'identity' in face2: + face1['identity'] = face2['identity'] + face2['identity']['members'].append(face) + else: + # print(f'Creating new identity {len(identities)} {face["between"]}') + identity = { + 'members': [], + } + face1['identity'] = face2['identity'] = identity + identity['members'].append(face) + identities.append(identity) + + for idx, identity in enumerate(identities): + count = len(identity['members']) + print('
') + print(f'
Identity {idx} has {count}
') + print('
') + for member in identity['members']: + face1 = member['between'][0] + face2 = member['between'][1] + print('
') + print(f'') + print(f'') + print('
') + print(f'
Distance: {member["distanceCosine"]}, {member["distanceEuclidian"]}, {member["distanceEuclidianL2"]}
') + print('
') + print('
') # update_face_count(conn, photoId, len(faces))