refactor: Face Cluster prefer Rust binary, remove global switch

- Remove MOMENTRY_USE_RUST_PROCESSORS from .env
- Face Cluster now tries Rust binary first, falls back to Python
- Appearance and Pose keep using Python (not needed currently)
- Simpler configuration: no global switch needed
This commit is contained in:
Accusys
2026-09-20 20:48:32 +08:00
parent ebee351523
commit d95857dcc7
+34 -31
View File
@@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
use std::time::Duration; use std::time::Duration;
use super::executor::PythonExecutor; use super::executor::PythonExecutor;
use crate::core::config::USE_RUST_PROCESSORS;
const FACE_CLUSTER_TIMEOUT: Duration = Duration::from_secs(3600); const FACE_CLUSTER_TIMEOUT: Duration = Duration::from_secs(3600);
@@ -93,39 +92,43 @@ pub async fn process_face_cluster(
); );
} }
// Rust processor path (MOMENTRY_USE_RUST_PROCESSORS=1) // Try Rust binary first (preferred), fallback to Python if unavailable
if *USE_RUST_PROCESSORS { if let Some(rust_bin) = executor.rust_binary_path("rust_face_cluster") {
if let Some(rust_bin) = executor.rust_binary_path("rust_face_cluster") { tracing::info!("[FACE_CLUSTER] Using Rust binary: {:?}", rust_bin);
tracing::info!("[FACE_CLUSTER] Using Rust binary: {:?}", rust_bin); match executor
executor .run_rust_with_output_idx_and_frames(
.run_rust_with_output_idx_and_frames( &rust_bin,
&rust_bin, &args,
&args, Some(1),
Some(1), uuid,
uuid, frames,
frames, "FACE_CLUSTER",
"FACE_CLUSTER", Some(FACE_CLUSTER_TIMEOUT),
Some(FACE_CLUSTER_TIMEOUT), )
) .await
.await {
.with_context(|| format!("Failed to run Rust binary {:?}", rust_bin))?; Ok(_) => {
let json_str = std::fs::read_to_string(output_path)
let json_str = std::fs::read_to_string(output_path) .context("Failed to read FACE_CLUSTER output")?;
.context("Failed to read FACE_CLUSTER output")?; let result: FaceClusterResult =
let result: FaceClusterResult = serde_json::from_str(&json_str).context("Failed to parse FACE_CLUSTER output")?;
serde_json::from_str(&json_str).context("Failed to parse FACE_CLUSTER output")?; tracing::info!(
tracing::info!( "[FACE_CLUSTER] Rust Result: {} clusters, {} frames",
"[FACE_CLUSTER] Rust Result: {} clusters, {} frames", result.clusters.len(),
result.clusters.len(), result.frames.len()
result.frames.len() );
); return Ok(result);
return Ok(result); }
Err(e) => {
tracing::warn!(
"[FACE_CLUSTER] Rust binary failed: {}, falling back to Python",
e
);
}
} }
tracing::warn!(
"[FACE_CLUSTER] MOMENTRY_USE_RUST_PROCESSORS=1 but rust_face_cluster binary not found, falling back to Python"
);
} }
// Fallback to Python script
executor executor
.run_with_output_idx_and_frames( .run_with_output_idx_and_frames(
"fast_face_clustering_processor.py", "fast_face_clustering_processor.py",