Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions backend/app/database/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ def db_insert_face_embeddings_by_image_id(
image_id, embeddings, confidence, bbox, cluster_id
)


def get_all_face_embeddings():
conn = sqlite3.connect(DATABASE_PATH)
cursor = conn.cursor()

try:
cursor.execute("""
cursor.execute(
"""
SELECT
f.embeddings,
f.bbox,
Expand All @@ -153,7 +155,8 @@ def get_all_face_embeddings():
JOIN images i ON f.image_id=i.id
LEFT JOIN image_classes ic ON i.id = ic.image_id
LEFT JOIN mappings m ON ic.class_id = m.class_id
""")
"""
)
results = cursor.fetchall()

images_dict = {}
Expand All @@ -173,7 +176,7 @@ def get_all_face_embeddings():
embeddings_json = json.loads(embeddings)
bbox_json = json.loads(bbox)
except json.JSONDecodeError:
continue;
continue
images_dict[image_id] = {
"embeddings": embeddings_json,
"bbox": bbox_json,
Expand Down Expand Up @@ -203,6 +206,7 @@ def get_all_face_embeddings():
finally:
conn.close()


def db_get_faces_unassigned_clusters() -> List[Dict[str, Union[FaceId, FaceEmbedding]]]:
"""
Get all faces that don't have assigned clusters.
Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/FaceDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def detect_faces(self, image_id: str, image_path: str, forSearch: bool = False):
embedding = self.facenet.get_embedding(processed_face)
embeddings.append(embedding)

if (not forSearch and embeddings):
if not forSearch and embeddings:
db_insert_face_embeddings_by_image_id(
image_id, embeddings, confidence=confidences, bbox=bboxes
)
Expand Down
29 changes: 25 additions & 4 deletions backend/app/routes/face_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,42 @@ def face_tagging(payload: AddSingleImageRequest):
image_id = str(uuid.uuid4())
result = fd.detect_faces(image_id, image_path, forSearch=True)
if not result or result["num_faces"] == 0:
return GetAllImagesResponse(success=True, message=f"Successfully retrieved {len(matches)} images", data=[])
return GetAllImagesResponse(
success=True,
message=f"Successfully retrieved {len(matches)} images",
data=[],
)

process_face = result["processed_faces"][0]
new_embedding = fn.get_embedding(process_face)

images = get_all_face_embeddings()
if len(images) == 0:
return GetAllImagesResponse(success=True, message=f"Successfully retrieved {len(matches)} images", data=[])
return GetAllImagesResponse(
success=True,
message=f"Successfully retrieved {len(matches)} images",
data=[],
)
else:
for image in images:
max_similarity = 0
similarity = FaceNet_util_cosine_similarity(new_embedding, image["embeddings"])
similarity = FaceNet_util_cosine_similarity(
new_embedding, image["embeddings"]
)
max_similarity = max(max_similarity, similarity)
if max_similarity >= CONFIDENCE_PERCENT:
matches.append(ImageData(id=image["id"], path=image["path"], folder_id=image["folder_id"], thumbnailPath=image["thumbnailPath"], metadata=image["metadata"], isTagged=image["isTagged"], tags=image["tags"], bboxes=image["bbox"]))
matches.append(
ImageData(
id=image["id"],
path=image["path"],
folder_id=image["folder_id"],
thumbnailPath=image["thumbnailPath"],
metadata=image["metadata"],
isTagged=image["isTagged"],
tags=image["tags"],
bboxes=image["bbox"],
)
)

return GetAllImagesResponse(
success=True,
Expand Down
1 change: 1 addition & 0 deletions backend/app/schemas/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FaceTaggingResponse(BaseModel):
message: str
data: dict


class ImagesResponse(BaseModel):
image_files: List[str]
folder_path: str
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/PersonImages/PersonImages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const PersonImages = () => {
</div>

{/* Media Viewer Modal */}
{isImageViewOpen && <MediaView />}
{isImageViewOpen && <MediaView images={images} />}
</div>
);
};
Loading