Recogition is off; face landmarks are not great. Maybe switch to other than retinaface and arcface
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
81e8a12546
commit
4263d18fec
@ -126,26 +126,28 @@ def l2_normalize(x):
|
|||||||
base = '/pictures/'
|
base = '/pictures/'
|
||||||
conn = create_connection('../db/photos.db')
|
conn = create_connection('../db/photos.db')
|
||||||
faces = {}
|
faces = {}
|
||||||
identities = {}
|
identities = []
|
||||||
|
|
||||||
with conn:
|
with conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
res = cur.execute('''
|
res = cur.execute('''
|
||||||
SELECT faces.id,facedescriptors.descriptors
|
SELECT faces.id,facedescriptors.descriptors,faces.faceConfidence,faces.photoId
|
||||||
FROM faces
|
FROM faces
|
||||||
JOIN facedescriptors ON (faces.descriptorId=facedescriptors.id)
|
JOIN facedescriptors ON (faces.descriptorId=facedescriptors.id)
|
||||||
WHERE faces.identityId IS null
|
WHERE faces.identityId IS null
|
||||||
''')
|
''')
|
||||||
for row in res.fetchall():
|
for row in res.fetchall():
|
||||||
id, descriptors = row
|
id, descriptors, confidence, photoId = row
|
||||||
if id in faces:
|
if id in faces:
|
||||||
face = faces[id]
|
face = faces[id]
|
||||||
else:
|
else:
|
||||||
face = {
|
face = {
|
||||||
'id': id,
|
'id': id,
|
||||||
'scanned': False
|
'scanned': False
|
||||||
}
|
}
|
||||||
faces[id] = face
|
faces[id] = face
|
||||||
|
face['confidence'] = confidence
|
||||||
|
face['photoId'] = photoId
|
||||||
face['descriptors'] = np.frombuffer(descriptors)
|
face['descriptors'] = np.frombuffer(descriptors)
|
||||||
|
|
||||||
for key1 in faces:
|
for key1 in faces:
|
||||||
@ -157,6 +159,8 @@ with conn:
|
|||||||
if key1 == key2:
|
if key1 == key2:
|
||||||
continue
|
continue
|
||||||
face2 = faces[key2]
|
face2 = faces[key2]
|
||||||
|
if face2['scanned']:
|
||||||
|
continue
|
||||||
face = {
|
face = {
|
||||||
'between': (face1['id'], face2['id'])
|
'between': (face1['id'], face2['id'])
|
||||||
}
|
}
|
||||||
@ -173,15 +177,49 @@ with conn:
|
|||||||
l2_normalize(face1['descriptors']),
|
l2_normalize(face1['descriptors']),
|
||||||
l2_normalize(face2['descriptors'])
|
l2_normalize(face2['descriptors'])
|
||||||
)
|
)
|
||||||
|
|
||||||
face['scoring'] = 0
|
face['scoring'] = 0
|
||||||
if face['distanceCosine'] >= 0.68:
|
if face['distanceCosine'] < 0.65:
|
||||||
face['scoring'] += 1
|
face['scoring'] += 1
|
||||||
if face['distanceEuclidian'] >= 4.15:
|
if face['distanceEuclidian'] < 4.00:
|
||||||
face['scoring'] += 1
|
face['scoring'] += 1
|
||||||
if face['distanceEuclidianL2'] >= 1.13:
|
if face['distanceEuclidianL2'] < 1.055:
|
||||||
face['scoring'] += 1
|
face['scoring'] += 1
|
||||||
|
|
||||||
if face['scoring'] == 3: # Same face!
|
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('<div>')
|
||||||
|
print(f'<div><b>Identity {idx} has {count}</b><br></div>')
|
||||||
|
print('<div>')
|
||||||
|
for member in identity['members']:
|
||||||
|
face1 = member['between'][0]
|
||||||
|
face2 = member['between'][1]
|
||||||
|
print('<div>')
|
||||||
|
print(f'<img src="faces/{face1%10}/{face1}.jpg"/>')
|
||||||
|
print(f'<img src="faces/{face2%10}/{face2}.jpg"/>')
|
||||||
|
print('</div>')
|
||||||
|
print(f'<div>Distance: {member["distanceCosine"]}, {member["distanceEuclidian"]}, {member["distanceEuclidianL2"]}</div>')
|
||||||
|
print('</div>')
|
||||||
|
print('</div>')
|
||||||
|
|
||||||
# update_face_count(conn, photoId, len(faces))
|
# update_face_count(conn, photoId, len(faces))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user