Skip to content

Commit

Permalink
Also add person labeled and person id when clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Jun 27, 2023
1 parent d59a6ce commit b547090
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 0 additions & 4 deletions api/cluster_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@


class ClusterManager:
@staticmethod
def get_global_data_count():
return Face.objects.count()

@staticmethod
def try_add_cluster(
user: User, cluster_id: int, faces: list[Face], padLen: int = 1
Expand Down
16 changes: 14 additions & 2 deletions api/face_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ def create_all_clusters(user: User, lrj: LongRunningJob = None) -> int:
print("[INFO] Creating clusters")

data = {
"all": {"encoding": [], "id": []},
"all": {"encoding": [], "id": [], "person_id": [], "person_labeled": []},
}
for face in Face.objects.filter(photo__owner=user).prefetch_related("person"):
data["all"]["encoding"].append(face.get_encoding_array())
data["all"]["id"].append(face.id)
data["all"]["person_id"].append(face.person.id)
data["all"]["person_labeled"].append(
1 if face.person.kind == Person.KIND_USER else 0
)

target_count = len(data["all"]["id"])
if target_count == 0:
Expand All @@ -139,7 +143,15 @@ def create_all_clusters(user: User, lrj: LongRunningJob = None) -> int:
# creating HDBSCAN object for clustering the encodings with the metric "euclidean"
clt = HDBSCAN(min_cluster_size=min_cluster_size, metric="euclidean")

clt.fit(np.array(data["all"]["encoding"]))
# clustering the encodings, person labeled and person_ids
X = np.column_stack(
(
np.array(data["all"]["encoding"]),
np.array(data["all"]["person_labeled"]),
np.array(data["all"]["person_id"]),
)
)
clt.fit(X)

labelIDs = np.unique(clt.labels_)
labelID: np.intp
Expand Down

0 comments on commit b547090

Please sign in to comment.