fix: handle both list and dict formats in store_traced_faces.py
問題: - face_clustering_processor.py 生成的 frames 是列表格式 - store_traced_faces.py 期望 frames 是字典格式 - 導致 AttributeError: 'list' object has no attribute 'items' 修復: - 添加格式判斷,支持列表和字典兩種格式 - 向後兼容舊格式 測試: - ✅ 腳本運行成功 - ✅ 不再報錯 影響: - Face Deduplication 可以正常執行 - 後續 TKG, Rule2, VLM Summary 可以繼續
This commit is contained in:
@@ -285,15 +285,32 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
|
||||
# Build trace_mapping for Qdrant update: {frame: {bbox_key: trace_id}}
|
||||
trace_mapping = {}
|
||||
for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])):
|
||||
frame_num = int(frame_num_str)
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
|
||||
# Handle both list and dict formats
|
||||
if isinstance(frames, list):
|
||||
# New format: frames is a list of frame objects
|
||||
for frame_data in frames:
|
||||
frame_num = frame_data.get("frame")
|
||||
if frame_num is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
else:
|
||||
# Old format: frames is a dict with frame numbers as keys
|
||||
for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])):
|
||||
frame_num = int(frame_num_str)
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
|
||||
# Update Qdrant _faces collection with trace_id.
|
||||
# return_trace_ids=True makes update_trace_ids also return the trace_id set seen
|
||||
@@ -310,12 +327,21 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
# Unique trace count from the update scroll (no extra full scan needed).
|
||||
qdrant_trace_count = len(trace_ids)
|
||||
|
||||
total_faces = sum(
|
||||
1
|
||||
for fd in frames.values()
|
||||
for f in fd.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
# Count total faces with trace_id
|
||||
if isinstance(frames, list):
|
||||
total_faces = sum(
|
||||
1
|
||||
for frame_data in frames
|
||||
for f in frame_data.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
else:
|
||||
total_faces = sum(
|
||||
1
|
||||
for fd in frames.values()
|
||||
for f in fd.get("faces", [])
|
||||
if f.get("trace_id") is not None
|
||||
)
|
||||
|
||||
print(
|
||||
f"[TRACE] Updated {qdrant_updated} Qdrant points with trace_id, {qdrant_trace_count} unique traces"
|
||||
|
||||
Reference in New Issue
Block a user