Skip to content

Commit

Permalink
fix face cluster not found row (#462)
Browse files Browse the repository at this point in the history
Co-authored-by: zheng.shen <[email protected]>
  • Loading branch information
shenzheng-1 and zheng.shen authored Jan 4, 2025
1 parent f979c2d commit 31558c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 5 additions & 3 deletions face_recognition/face_recognition_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from seafevents.db import init_db_session_class
from seafevents.repo_metadata.metadata_server_api import MetadataServerAPI
from seafevents.repo_metadata.image_embedding_api import ImageEmbeddingAPI
from seafevents.repo_metadata.utils import query_metadata_rows
from seafevents.repo_metadata.utils import query_metadata_rows, get_metadata_by_row_ids
from seafevents.repo_metadata.constants import METADATA_TABLE, FACES_TABLE
from seafevents.face_recognition.constants import UNKNOWN_PEOPLE_NAME
from seafevents.face_recognition.utils import get_faces_rows, get_cluster_by_center, b64encode_embeddings, \
Expand Down Expand Up @@ -187,17 +187,19 @@ def face_cluster(self, repo_id):
if face_row:
face_row[FACES_TABLE.columns.id.name] = cluster_id
self.metadata_server_api.update_rows(repo_id, faces_table_id, [face_row])
exist_rows = get_metadata_by_row_ids(repo_id, related_row_ids, self.metadata_server_api)
row_id_map = {
cluster_id: related_row_ids
cluster_id: [item[METADATA_TABLE.columns.id.name] for item in exist_rows]
}
self.metadata_server_api.update_link(repo_id, FACES_TABLE.face_link_id, faces_table_id, row_id_map)

for value in label_id_to_added_cluster.values():
face_row, related_row_ids, cluster_center = value
result = self.metadata_server_api.insert_rows(repo_id, faces_table_id, [face_row])
face_row_id = result.get('row_ids')[0]
exist_rows = get_metadata_by_row_ids(repo_id, related_row_ids, self.metadata_server_api)
row_id_map = {
face_row_id: related_row_ids
face_row_id: [item[METADATA_TABLE.columns.id.name] for item in exist_rows]
}
self.metadata_server_api.insert_link(repo_id, FACES_TABLE.face_link_id, faces_table_id, row_id_map)

Expand Down
21 changes: 20 additions & 1 deletion repo_metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def gen_select_options(option_names):
return options



def gen_option_id(id_set):
_id = str(math.floor(random.uniform(0.1, 1) * (10 ** 6)))

Expand Down Expand Up @@ -272,6 +271,25 @@ def get_metadata_by_obj_ids(repo_id, obj_ids, metadata_server_api):
return query_result


def get_metadata_by_row_ids(repo_id, row_ids, metadata_server_api):
sql = f'SELECT * FROM `{METADATA_TABLE.name}` WHERE `{METADATA_TABLE.columns.id.name}` IN ('
parameters = []

for row_id in row_ids:
sql += '?, '
parameters.append(row_id)

if not parameters:
return []
sql = sql.rstrip(', ') + ');'
query_result = metadata_server_api.query_rows(repo_id, sql, parameters).get('results', [])

if not query_result:
return []

return query_result


def query_metadata_rows(repo_id, metadata_server_api, sql):
rows = []
offset = 10000
Expand All @@ -289,6 +307,7 @@ def query_metadata_rows(repo_id, metadata_server_api, sql):

return rows


def gen_view_data_sql(table, columns, view, start, limit, params):
""" generate view data sql """
return view_data_2_sql(table, columns, view, start, limit, params)
Expand Down

0 comments on commit 31558c9

Please sign in to comment.