fix: face pipeline 三項修復
1. face_clustering: 先試 Rust binary,Python script 缺失不再提前返回空結果 2. face.rs: facenet model 查找加 fallback ( -> momentry_core/models),config 路徑補 --model 參數 3. rust_store_traced_faces: embedding 缺失時退回純 IoU 追蹤(不再強制要求 similarity);trace_profile.json 補上真實 avg_bbox/best_bbox/capture_quality
This commit is contained in:
+33
-11
@@ -8,6 +8,24 @@ use super::FaceStatus;
|
||||
|
||||
const FACE_TIMEOUT: Duration = Duration::from_secs(7200);
|
||||
|
||||
/// Resolve the FaceNet512 CoreML model path.
|
||||
/// Priority: $MOMENTRY_MODELS_DIR/facenet512.mlpackage -> momentry_core/models/facenet512.mlpackage
|
||||
pub fn facenet_model_path() -> Option<std::path::PathBuf> {
|
||||
use std::path::PathBuf;
|
||||
let env_dir = std::env::var("MOMENTRY_MODELS_DIR")
|
||||
.ok()
|
||||
.map(PathBuf::from);
|
||||
let candidates = [
|
||||
env_dir.map(|d| d.join("facenet512.mlpackage")),
|
||||
Some(
|
||||
crate::core::path_utils::momentry_core_dir()
|
||||
.join("models")
|
||||
.join("facenet512.mlpackage"),
|
||||
),
|
||||
];
|
||||
candidates.into_iter().flatten().find(|p| p.exists())
|
||||
}
|
||||
|
||||
pub fn swift_processor_path(bin: &str) -> std::path::PathBuf {
|
||||
use std::path::PathBuf;
|
||||
let rel = format!(".build/release/{}", bin);
|
||||
@@ -323,16 +341,14 @@ pub async fn process_face(
|
||||
if facenet_path.exists() {
|
||||
tracing::info!("[FACE] Generating embeddings with FaceNet CoreML");
|
||||
|
||||
// Resolve model path
|
||||
let models_dir =
|
||||
crate::core::path_utils::resolve_asset_path("MOMENTRY_MODELS_DIR", "models");
|
||||
let model_path = models_dir.join("facenet512.mlpackage");
|
||||
|
||||
if !model_path.exists() {
|
||||
tracing::error!("[FACE] FaceNet model not found at {:?}", model_path);
|
||||
tracing::error!("[FACE] Set MOMENTRY_MODELS_DIR environment variable or ensure models/facenet512.mlpackage exists");
|
||||
anyhow::bail!("FaceNet model not found - cannot generate embeddings");
|
||||
}
|
||||
// Resolve model path (env dir -> momentry_core/models fallback)
|
||||
let model_path = match facenet_model_path() {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
tracing::error!("[FACE] FaceNet model not found (checked $MOMENTRY_MODELS_DIR and momentry_core/models)");
|
||||
anyhow::bail!("FaceNet model not found - cannot generate embeddings");
|
||||
}
|
||||
};
|
||||
|
||||
let facenet_output = format!("{}.with_embedding", output_path);
|
||||
let facenet_args = vec![
|
||||
@@ -549,11 +565,17 @@ async fn run_face_with_config(
|
||||
tracing::info!("[FACE] Generating embeddings with FaceNet CoreML");
|
||||
|
||||
let facenet_output = format!("{}.with_embedding", output_path);
|
||||
let facenet_args = vec![
|
||||
let mut facenet_args = vec![
|
||||
video_path.to_string(),
|
||||
output_path.to_string(),
|
||||
facenet_output.clone(),
|
||||
];
|
||||
// Explicit --model (the binary otherwise derives the path from
|
||||
// MOMENTRY_MODELS_DIR, which may not contain facenet512)
|
||||
if let Some(model_path) = facenet_model_path() {
|
||||
facenet_args.push("--model".to_string());
|
||||
facenet_args.push(model_path.to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
let facenet_result = tokio::process::Command::new(facenet_path)
|
||||
.args(&facenet_args)
|
||||
|
||||
@@ -159,11 +159,14 @@ pub async fn process_face_cluster(
|
||||
similarity_threshold: Option<f64>,
|
||||
) -> Result<FaceClusterResult> {
|
||||
let executor = PythonExecutor::new()?;
|
||||
let script_path = executor.script_path("fast_face_clustering_processor.py");
|
||||
|
||||
tracing::info!("[FACE_CLUSTER] Starting face clustering: {}", video_path);
|
||||
|
||||
if !script_path.exists() {
|
||||
// Try Rust binary first (preferred); legacy Python script is only a fallback.
|
||||
// Do NOT bail early just because the Python script is missing — that would
|
||||
// skip the Rust binary even when it exists.
|
||||
let script_path = executor.script_path("fast_face_clustering_processor.py");
|
||||
if executor.rust_binary_path("rust_face_cluster").is_none() && !script_path.exists() {
|
||||
tracing::warn!("[FACE_CLUSTER] Script not found, returning empty result");
|
||||
return Ok(FaceClusterResult {
|
||||
schema_version: "2.0".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user