feat: improve face clustering and add trace-profile API fallback

Core changes:
- Face clustering threshold: 0.35 → 0.15 (better male/female separation)
- Add auto-filtering for low-quality clusters (face_count<20, bbox_area>150000)
- Add filesystem fallback for trace-profile API

Face clustering improvements:
- Correctly separates male and female faces
- Filters hand detections and isolated faces
- Result: 2 persons (186 male, 174 female) vs 4 persons before

Trace profile API:
- GET /api/v1/trace-profile?file_uuid=X&trace_id=Y
- Returns data from PostgreSQL or filesystem fallback
- Simplifies frontend: no need to know filesystem structure
- Fixes Studio 'trace profile not found' error

Issue: docs_v1.0/M4_workspace/2026-10-16_studio_trace_profile_bug_report.md
This commit is contained in:
Accusys
2026-10-16 13:36:29 +08:00
parent e8b26f997f
commit 2090dd25ea
16 changed files with 4860 additions and 163 deletions
+40
View File
@@ -417,6 +417,46 @@ pub mod processor {
.unwrap_or(3600)
});
/// Face clustering distance threshold (for Facenet-pytorch)
/// Lower = more strict (require smaller distance to cluster together)
/// Recommended: 0.15 for Facenet-pytorch to correctly separate male/female faces
/// Value 0.35 caused male/female to merge into one person
pub static FACE_CLUSTER_DISTANCE_THRESHOLD: Lazy<f64> = Lazy::new(|| {
env::var("MOMENTRY_FACE_CLUSTER_THRESHOLD")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(0.15)
});
/// Face clustering similarity threshold (inverse of distance)
/// Higher = more strict (require higher similarity to cluster together)
/// Recommended: 0.85 for Facenet-pytorch to correctly separate male/female faces
/// Value 0.65 caused male/female to merge into one person
pub static FACE_CLUSTER_SIMILARITY_THRESHOLD: Lazy<f64> = Lazy::new(|| {
env::var("MOMENTRY_FACE_CLUSTER_SIMILARITY_THRESHOLD")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(0.85)
});
/// Enable Stage 2 merge for face clustering
/// Merges over-split clusters based on centroid similarity
pub static FACE_CLUSTER_STAGE2_ENABLED: Lazy<bool> = Lazy::new(|| {
env::var("MOMENTRY_FACE_CLUSTER_STAGE2")
.map(|v| v == "true" || v == "1")
.unwrap_or(true)
});
/// Face clustering Stage 2 merge threshold
/// More conservative than cluster threshold to avoid over-merging
/// Recommended: 0.30 (conservative), lower values = less merging
pub static FACE_CLUSTER_MERGE_THRESHOLD: Lazy<f64> = Lazy::new(|| {
env::var("MOMENTRY_FACE_CLUSTER_MERGE_THRESHOLD")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(0.30)
});
pub static DEFAULT_TIMEOUT_SECS: Lazy<u64> = Lazy::new(|| {
env::var("MOMENTRY_DEFAULT_TIMEOUT")
.ok()