BUG: face search misses everyone but the first face in a group photo
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
Face search only compares the first stored face of a photo. Anyone who is not the first detected face in a group shot cannot be found at all.
Reproduced with the photos already in the repo. The detector finds 3 faces in tests/inputs/three_khans.png, and neither shipped portrait matches face 0:
amir_khan.png cosine vs the 3 faces [0.257, 0.713, 0.348] -> face 1
salman_khan.png cosine vs the 3 faces [0.124, 0.235, 0.836] -> face 2
Searching with salman_khan.png returns 0 results even though he is in the library. Searching with amir_khan.png returns only his solo portrait and not the group photo.
The cause is get_all_face_embeddings in backend/app/database/faces.py. It keys its result by image_id, so a photo with N faces collapses into one row and the other embeddings are dropped. The same loop appends tags once per join row, so a photo with 3 faces and 3 tags comes back with 9 tag entries instead of 3.
A face row with a null bbox also kills the whole search, because json.loads(None) raises TypeError and only JSONDecodeError is caught.
Steps to reproduce:
- Add a folder with a group photo plus a solo portrait of someone who is not the first face detected in it
- Let AI tagging finish
- Search by face using the solo portrait
- The group photo is missing from the results
Not a duplicate of #1164. That one is about clusters showing fewer photos than search. This one is search itself returning too few.
Record
- [x] I agree to follow this project's Code of Conduct
👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
BUG: Face clusters show fewer photos than face search for the same person (#1164, open) https://github.com/AOSSIE-Org/PictoPy/issues/1164 Similarity: 66.3%
-
BUG: Face Clustering Algorithm Fails to Detect Similar/Identical Faces (#348, closed) https://github.com/AOSSIE-Org/PictoPy/issues/348 Similarity: 65.6%
-
BUG: Face Clustering Quality Issues (#793, closed) https://github.com/AOSSIE-Org/PictoPy/issues/793 Similarity: 65.1%
Please review before proceeding.
Link your account with Gitcord
Thanks for opening this issue, @harshvardhanrp!
To receive Discord notifications and contributor tracking for this organization:
- Join Discord: https://discord.gg/hjUhu33uAn
- In Discord, run
/link harshvardhanrp - Paste the verification code into your GitHub bio (or a public gist)
- Click Verify in Discord (or run
/verify-link harshvardhanrp)
Once linked, Gitcord can notify you about assignments, mentions, and more.
— Posted by Gitcord