fix: resolve FaceNet model path at runtime (A-4.2 P1, A-11, A-12)

Issues:
- facenet_embedding.swift:28 hardcoded model path
- face.rs:227-231 did not pass model path parameter
- face.rs:249-255 only logged warnings, causing silent degradation
- M4ProMini missing facenet512.mlpackage → embeddings all None → TKG 0 nodes

Changes:
1. facenet_embedding.swift:
   - Add --model option (default: models/facenet512.mlpackage)
   - Validate model file exists before loading
   - Print clear error message if missing

2. face.rs:
   - Use path_utils::resolve_asset_path for models dir
   - Pass --model argument to facenet_embedding
   - Validate model exists before running
   - Elevate errors from warn! to error! + bail!
   - Fail fast on embedding generation failure

Benefits:
- Runtime resolution via MOMENTRY_MODELS_DIR
- No silent degradation - missing model causes explicit error
- Clear error messages guide users to fix

Verification:
- cargo check --lib passes
- swift build -c release passes

Next steps:
- Add facenet512.mlpackage to release delivery (A-11 requirement 3)
- Update smoketest to verify embeddings != None (A-5.3)

References:
- A-4.2 P1 in Momentry_Release_Requirements_20261004.md v1.1
- A-11, A-12
- 020.mp4 diagnosis (appendix C)
This commit is contained in:
Accusys
2026-10-04 14:37:49 +08:00
parent b331a3d0cd
commit 3399a137d8
2 changed files with 36 additions and 5 deletions
+23 -3
View File
@@ -223,11 +223,23 @@ let swift_face_path = swift_processor_path("swift_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");
}
let facenet_output = format!("{}.with_embedding", output_path);
let facenet_args = vec![
video_path.to_string(),
output_path.to_string(),
facenet_output.clone(),
"--model".to_string(),
model_path.to_string_lossy().to_string(),
];
let facenet_result = tokio::process::Command::new(facenet_path)
@@ -240,20 +252,28 @@ let swift_face_path = swift_processor_path("swift_face");
// Replace original file with embedding-enhanced version
if std::path::Path::new(&facenet_output).exists() {
if let Err(e) = std::fs::copy(&facenet_output, output_path) {
tracing::warn!("[FACE] Failed to copy embedding file: {}", e);
tracing::error!("[FACE] Failed to copy embedding file: {}", e);
anyhow::bail!("Failed to copy embedding file: {}", e);
} else {
tracing::info!("[FACE] Embeddings generated successfully");
}
} else {
tracing::error!("[FACE] FaceNet output file not created: {}", facenet_output);
anyhow::bail!("FaceNet output file not created");
}
}
Ok(output) => {
let stderr = String::from_utf8_lossy(&output.stderr);
tracing::warn!("[FACE] FaceNet embedding failed: {}", stderr);
tracing::error!("[FACE] FaceNet embedding failed: {}", stderr);
anyhow::bail!("FaceNet embedding failed: {}", stderr);
}
Err(e) => {
tracing::warn!("[FACE] FaceNet embedding error: {}", e);
tracing::error!("[FACE] FaceNet embedding error: {}", e);
anyhow::bail!("FaceNet embedding error: {}", e);
}
}
} else {
tracing::warn!("[FACE] FaceNet binary not found at {:?}, skipping embedding generation", facenet_path);
}
// Read the JSON (with embeddings from FaceNet)