feat: implement Rust face_tracker module
- Add face_tracker.rs with core tracking algorithms - Add trace_id field to Face struct - Add metadata field to FaceResult struct - Implement IoU, distance, and embedding similarity calculations - Implement match_faces and track_faces functions - Support scene cut detection - Add unit tests for core functions
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
# 020.mp4 Ingestion 卡住問題最終分析
|
||||
|
||||
**日期**: 2026-09-27
|
||||
**視頻**: 020.mp4 (UUID: b496a68800f90770aa7246c877f38985)
|
||||
**狀態**: ❌ Ingestion 卡在 40% (待修復)
|
||||
|
||||
---
|
||||
|
||||
## 問題鏈完整分析
|
||||
|
||||
### 問題 1: Face.json 格式變更 ❌
|
||||
|
||||
**現象**: `face.json` 的 `frames` 從 dict 改為 list
|
||||
|
||||
**影響**: `face_tracker.py` 期望 dict 格式,報錯
|
||||
|
||||
**修復**: ✅ 已修復
|
||||
- 添加了對 list 格式的支持
|
||||
- 自動轉換為 dict 格式
|
||||
|
||||
**提交**: `696ede8`
|
||||
|
||||
---
|
||||
|
||||
### 問題 2: Qdrant bbox 信息錯誤 ❌ (根本原因)
|
||||
|
||||
**現象**: Qdrant 中的 bbox 信息都是 `x=0, y=0, width=0, height=0`
|
||||
|
||||
**檢查**:
|
||||
```bash
|
||||
curl -X POST -H "api-key: Test3200Test3200Test3200" \
|
||||
"http://127.0.0.1:6333/collections/_faces/points/scroll" \
|
||||
-d '{"limit": 1, "filter": {"must": [{"key": "file_uuid", "match": {"value": "b496a68800f90770aa7246c877f38985"}}]}}'
|
||||
```
|
||||
|
||||
**結果**:
|
||||
```json
|
||||
{
|
||||
"payload": {
|
||||
"file_uuid": "b496a68800f90770aa7246c877f38985",
|
||||
"frame": 480,
|
||||
"x": 0, "y": 0, "width": 0, "height": 0, // ❌ 錯誤!
|
||||
"trace_id": -1
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**原因**: `store_face_embeddings_to_qdrant.py` 存儲時使用了錯誤的 bbox 信息
|
||||
|
||||
**影響**:
|
||||
1. `store_traced_faces.py` 無法正確匹配 embeddings
|
||||
2. `emb_lookup` 構建失敗
|
||||
3. Face tracking 缺少 embeddings
|
||||
4. 追蹤質量下降
|
||||
|
||||
---
|
||||
|
||||
### 問題 3: Embedding 匹配失敗 ❌
|
||||
|
||||
**現象**: `Attached 0 embeddings to face data`
|
||||
|
||||
**根本原因**:
|
||||
```python
|
||||
# store_traced_faces.py 中的匹配邏輯
|
||||
emb_lookup[(frame, x, y)] = vec
|
||||
|
||||
# Qdrant 中的 key: (480, 0, 0)
|
||||
# face.json 中的 key: (480, 1377, 219)
|
||||
# 不匹配!
|
||||
```
|
||||
|
||||
**影響**:
|
||||
- Face tracking 沒有 embeddings
|
||||
- 追蹤算法降級為只用 IoU + 距離
|
||||
- 追蹤質量下降
|
||||
|
||||
---
|
||||
|
||||
### 問題 4: trace_id 未更新到 Qdrant ❌
|
||||
|
||||
**現象**: `Updated 0 Qdrant points with trace_id`
|
||||
|
||||
**原因**:
|
||||
1. `update_trace_ids()` 依賴 bbox 匹配
|
||||
2. Qdrant 中的 bbox 信息錯誤
|
||||
3. 無法匹配 faces
|
||||
|
||||
**影響**:
|
||||
- TKG builder 找不到 traced faces
|
||||
- TKG 無法構建
|
||||
- Ingestion 卡住
|
||||
|
||||
---
|
||||
|
||||
## 根本原因
|
||||
|
||||
**`store_face_embeddings_to_qdrant.py` 的 bbox 存儲問題**:
|
||||
|
||||
```python
|
||||
# Line 66-77
|
||||
payload = {
|
||||
"file_uuid": file_uuid,
|
||||
"frame": frame_num,
|
||||
"timestamp_secs": timestamp,
|
||||
"face_id": face.get("face_id", ""),
|
||||
"confidence": face.get("confidence", 0.0),
|
||||
"x": face.get("x", 0), # ❌ 如果 face 中沒有這些字段,就是 0
|
||||
"y": face.get("y", 0), # ❌
|
||||
"width": face.get("width", 0), # ❌
|
||||
"height": face.get("height", 0), # ❌
|
||||
"trace_id": -1,
|
||||
}
|
||||
```
|
||||
|
||||
**問題**: face.json 的結構可能沒有直接的 x, y, width, height 字段
|
||||
|
||||
---
|
||||
|
||||
## 修復方案
|
||||
|
||||
### 方案 1: 修復 store_face_embeddings_to_qdrant.py
|
||||
|
||||
**檢查 face.json 的實際結構**:
|
||||
```python
|
||||
# 檢查 face 是否有 bbox 字段
|
||||
bbox = face.get("bbox", {})
|
||||
if bbox:
|
||||
x = bbox.get("x", 0)
|
||||
y = bbox.get("y", 0)
|
||||
width = bbox.get("width", 0)
|
||||
height = bbox.get("height", 0)
|
||||
else:
|
||||
x = face.get("x", 0)
|
||||
y = face.get("y", 0)
|
||||
width = face.get("width", 0)
|
||||
height = face.get("height", 0)
|
||||
```
|
||||
|
||||
### 方案 2: 修復 update_trace_ids() 匹配邏輯
|
||||
|
||||
**不依賴 bbox,改用 frame 匹配**:
|
||||
```python
|
||||
# 構建 trace_mapping
|
||||
trace_mapping = {}
|
||||
for trace_id, trace_data in traces.items():
|
||||
start_frame = trace_data["start_frame"]
|
||||
end_frame = trace_data["end_frame"]
|
||||
|
||||
# 對於每個 frame,找到該 frame 的所有 faces
|
||||
for frame in range(start_frame, end_frame + 1):
|
||||
if frame not in trace_mapping:
|
||||
trace_mapping[frame] = {}
|
||||
|
||||
# 從 face_traced.json 的 frames 中找到該 frame 的 faces
|
||||
# 根據 face index 匹配
|
||||
```
|
||||
|
||||
### 方案 3: 重新生成 embeddings
|
||||
|
||||
**刪除舊的 Qdrant points,重新生成**:
|
||||
```bash
|
||||
# 1. 刪除該文件的所有 points
|
||||
curl -X POST -H "api-key: Test3200Test3200Test3200" \
|
||||
"http://127.0.0.1:6333/collections/_faces/points/delete" \
|
||||
-d '{"filter": {"must": [{"key": "file_uuid", "match": {"value": "b496a68800f90770aa7246c877f38985"}}]}}'
|
||||
|
||||
# 2. 重新運行 store_face_embeddings_to_qdrant.py
|
||||
python3 scripts/store_face_embeddings_to_qdrant.py --file-uuid b496a68800f90770aa7246c877f38985
|
||||
|
||||
# 3. 重新運行 store_traced_faces.py
|
||||
python3 scripts/store_traced_faces.py --file-uuid b496a68800f90770aa7246c877f38985 --uuid b496a68800f90770aa7246c877f38985
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 當前狀態
|
||||
|
||||
### 已修復 ✅
|
||||
1. ✅ face_tracker.py 支持 list 格式
|
||||
2. ✅ update_trace_ids() 支持兩種 bbox 格式
|
||||
|
||||
### 待修復 ❌
|
||||
1. ❌ store_face_embeddings_to_qdrant.py bbox 存儲
|
||||
2. ❌ 重新生成 020.mp4 的 embeddings
|
||||
3. ❌ 更新 Qdrant trace_id
|
||||
|
||||
---
|
||||
|
||||
## 下一步
|
||||
|
||||
### 立即執行
|
||||
1. ✅ 檢查 face.json 的實際結構
|
||||
2. ✅ 修復 store_face_embeddings_to_qdrant.py
|
||||
3. ✅ 重新生成 embeddings
|
||||
4. ✅ 驗證 trace_id 更新
|
||||
|
||||
### 長期改進
|
||||
1. 統一 bbox 存儲格式
|
||||
2. 添加更多的調試日誌
|
||||
3. 添加單元測試
|
||||
|
||||
---
|
||||
|
||||
**分析完成時間**: 2026-09-27 01:20:00 UTC
|
||||
Reference in New Issue
Block a user