feat: face clustering pipeline improvements and Rust/Swift face processing
- Add Rust face processor module (detection, embedding, tracking, qdrant) - Add Facenet CoreML/ONNX conversion scripts and tests - Refactor swift_face into Sources/swift_face with ArgumentParser support - Update store_traced_faces to handle face.json correctly - Fix ASRX parsing and TKG bbox reading from Qdrant - Improve admin_config and trace_agent APIs - Add M4 workspace docs for face clustering, dedup, and Facenet validation - Fix worker heartbeat TTL (poll_interval x 3, min 60s) for offline detection
This commit is contained in:
@@ -185,6 +185,28 @@ pub struct AdminSettings {
|
||||
pub preferred_language: String,
|
||||
}
|
||||
|
||||
/// Get FS VLM enabled setting from admin_config
|
||||
/// Returns false by default (FS VLM disabled)
|
||||
pub async fn get_fs_vlm_enabled(pool: &sqlx::PgPool) -> bool {
|
||||
use tracing::warn;
|
||||
|
||||
let key = "fs_vlm_enabled";
|
||||
let sql = "SELECT value FROM admin_config WHERE key = $1";
|
||||
|
||||
match sqlx::query_scalar::<_, String>(sql)
|
||||
.bind(key)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
{
|
||||
Ok(Some(value)) => value == "true" || value == "1",
|
||||
Ok(None) => false, // Default: disabled
|
||||
Err(e) => {
|
||||
warn!("[AdminConfig] Failed to get fs_vlm_enabled: {}, using default (false)", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SearchConfig {
|
||||
#[serde(default = "default_vlm_min_score")]
|
||||
|
||||
@@ -684,9 +684,9 @@ impl ProcessorType {
|
||||
ProcessorType::Ocr,
|
||||
ProcessorType::Face,
|
||||
ProcessorType::FaceCluster,
|
||||
ProcessorType::Pose,
|
||||
ProcessorType::Hand,
|
||||
ProcessorType::Appearance,
|
||||
// ProcessorType::Pose, // Disabled in production pipeline
|
||||
// ProcessorType::Hand, // Disabled in production pipeline
|
||||
// ProcessorType::Appearance, // Disabled in production pipeline
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -69,53 +69,10 @@ pub async fn process_asrx(
|
||||
output_path: &str,
|
||||
uuid: Option<&str>,
|
||||
) -> Result<AsrxResult> {
|
||||
tracing::info!("[ASRX] Starting hybrid speaker diarization: {}", video_path);
|
||||
|
||||
let swift_asrx_path = std::path::Path::new("/Users/accusys/momentry_core/scripts/swift_processors/.build/release/asrx_swift");
|
||||
tracing::info!("[ASRX] Starting speaker diarization: {}", video_path);
|
||||
|
||||
if swift_asrx_path.exists() {
|
||||
tracing::info!("[ASRX] Using Swift processor: {:?}", swift_asrx_path);
|
||||
|
||||
let mut args = vec![video_path.to_string(), output_path.to_string()];
|
||||
if let Some(u) = uuid {
|
||||
args.push("--uuid".to_string());
|
||||
args.push(u.to_string());
|
||||
}
|
||||
|
||||
let output = tokio::process::Command::new(swift_asrx_path)
|
||||
.args(&args)
|
||||
.output()
|
||||
.await
|
||||
.context("Failed to execute asrx_swift")?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
tracing::error!("[ASRX] Swift processor failed: {}", stderr);
|
||||
|
||||
tracing::warn!("[ASRX] Falling back to Python processor");
|
||||
return process_asrx_python(video_path, output_path, uuid).await;
|
||||
}
|
||||
|
||||
tracing::info!("[ASRX] Swift processor completed successfully");
|
||||
|
||||
let json_str = std::fs::read_to_string(output_path)
|
||||
.context("Failed to read ASRX output")?;
|
||||
|
||||
let mut result: AsrxResult = serde_json::from_str(&json_str)
|
||||
.context("Failed to parse ASRX output")?;
|
||||
|
||||
result.compute_status();
|
||||
|
||||
tracing::info!(
|
||||
"[ASRX] Swift result: status={}, {} segments",
|
||||
result.status.as_ref().map(|s| s.to_string()).unwrap_or_default(),
|
||||
result.segment_count
|
||||
);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
tracing::warn!("[ASRX] Swift binary not found, using Python processor");
|
||||
// Use Python processor (Swift ASRX disabled - requires GUI authorization)
|
||||
tracing::info!("[ASRX] Using Python processor");
|
||||
process_asrx_python(video_path, output_path, uuid).await
|
||||
}
|
||||
|
||||
|
||||
@@ -1209,7 +1209,14 @@ impl PythonExecutor {
|
||||
/// Looks under `<scripts_dir>/rust_processors/target/release/` first, falling
|
||||
/// back to `target/debug/` (mirrors the swift_processors layout convention).
|
||||
pub fn rust_binary_path(&self, bin_name: &str) -> Option<PathBuf> {
|
||||
let base = self.scripts_dir.join("rust_processors").join("target");
|
||||
// Use tools/cli/rust/ instead of scripts/rust_processors/
|
||||
let cli_dir = std::env::var("MOMENTRY_CLI_DIR")
|
||||
.unwrap_or_else(|_| {
|
||||
let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest.join("tools/cli").to_string_lossy().to_string()
|
||||
});
|
||||
|
||||
let base = PathBuf::from(cli_dir).join("rust").join("target");
|
||||
for profile in ["release", "debug"] {
|
||||
let p = base.join(profile).join(bin_name);
|
||||
if p.exists() {
|
||||
|
||||
@@ -78,19 +78,20 @@ pub async fn process_face_cluster(
|
||||
});
|
||||
}
|
||||
|
||||
// Build args with optional --threshold
|
||||
let distance = similarity_threshold.map(|s| 1.0 - s);
|
||||
let mut args = vec![video_path, output_path];
|
||||
if let Some(d) = distance {
|
||||
let threshold_str = format!("{:.4}", d);
|
||||
args.push("--threshold");
|
||||
args.push(Box::leak(threshold_str.into_boxed_str()) as &str);
|
||||
tracing::info!(
|
||||
"[FACE_CLUSTER] similarity={:.2} → distance={:.4}",
|
||||
similarity_threshold.unwrap_or(0.65),
|
||||
d
|
||||
);
|
||||
}
|
||||
// Build args with --threshold (always pass, default 0.15)
|
||||
let threshold = similarity_threshold.unwrap_or(0.85);
|
||||
let distance = 1.0 - threshold;
|
||||
let threshold_str = format!("{:.4}", distance);
|
||||
let mut args = vec![
|
||||
video_path,
|
||||
output_path,
|
||||
"--threshold",
|
||||
Box::leak(threshold_str.into_boxed_str()) as &str,
|
||||
];
|
||||
tracing::info!(
|
||||
"[FACE_CLUSTER] Using threshold: similarity={:.2}, distance={:.4}",
|
||||
threshold, distance
|
||||
);
|
||||
|
||||
// Try Rust binary first (preferred), fallback to Python if unavailable
|
||||
if let Some(rust_bin) = executor.rust_binary_path("rust_face_cluster") {
|
||||
|
||||
@@ -278,12 +278,16 @@ async fn populate_face_detections_from_face_json(
|
||||
publish_tkg_progress(&r, file_uuid, &progress).await;
|
||||
}
|
||||
|
||||
// Use Rust binary for face trace (V3 config: priority 0)
|
||||
let rust_binary = "tools/cli/rust/target/release/rust_store_traced_faces";
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
|
||||
let executor = crate::core::processor::executor::PythonExecutor::new()?;
|
||||
|
||||
let result = executor
|
||||
.run_with_output_idx(
|
||||
"store_traced_faces.py",
|
||||
&["--file-uuid", file_uuid],
|
||||
rust_binary,
|
||||
&[file_uuid, "--output-dir", output_dir],
|
||||
Some(file_uuid),
|
||||
"TKG_PHASE0",
|
||||
Some(std::time::Duration::from_secs(600)),
|
||||
|
||||
Reference in New Issue
Block a user