more clustering

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-06 20:27:32 -08:00
parent 0e7dbd5239
commit 3b3c915080

View File

@ -193,17 +193,36 @@ def update_face_identity(identities, face, closest):
def cluster_faces(face):
identities = []
perc = -1
for i, face in enumerate(faces):
print(f'Clustering {i+1}/{len(faces)}')
new_perc = int(100 * (i+1) / len(faces))
if new_perc != perc:
perc = new_perc
print(f'Clustering faces {perc}% complete with {len(identities)} identities.')
closest = find_nearest_face(faces, identities, face, threshold = 0.25)
if closest == None:
print(f'Face {i+1} does not have any matches.')
continue
identity = update_face_identity(identities, face, closest)
# if identity['faces'] > 2:
# print(f'Updated identity {identity["id"]} to hold {identity["faces"]} faces.')
return identities
def cluster_identities(identities):
perc = -1
last_len = 0
while last_len != len(identities):
last_len = len(identities)
for i, identity in enumerate(identities):
new_perc = int(100 * (i+1) / len(identities))
if new_perc != perc:
perc = new_perc
print(f'Clustering identities {perc}% complete with {len(identities)} identities.')
closest = find_nearest_face([], identities, face, threshold = 0.25)
if closest == None:
continue
update_face_identity(identities, identity, closest)
return identities
def identity_get_faces(item):
return item['faces']
@ -233,11 +252,14 @@ with conn:
face['descriptors'] = np.frombuffer(descriptors)
identities = cluster_faces(faces)
#identities = cluster_identities(identities)
identities.sort(reverse = True, key = identity_get_faces)
sum = 0
for identity in identities:
sum += identity['faces']
print(f'{identity["id"]} has {identity["faces"]} faces')
print(f'{len(identities)} identities seeded.')
print(f'{len(identities)} identities seeded with {sum} faces.')
exit(0)
if False: