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:
@@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
|
||||
use super::executor::PythonExecutor;
|
||||
use crate::core::config::USE_RUST_PROCESSORS;
|
||||
|
||||
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)
|
||||
if *USE_RUST_PROCESSORS {
|
||||
if let Some(rust_bin) = executor.rust_binary_path("rust_face_cluster") {
|
||||
tracing::info!("[FACE_CLUSTER] Using Rust binary: {:?}", rust_bin);
|
||||
executor
|
||||
.run_rust_with_output_idx_and_frames(
|
||||
&rust_bin,
|
||||
&args,
|
||||
Some(1),
|
||||
uuid,
|
||||
frames,
|
||||
"FACE_CLUSTER",
|
||||
Some(FACE_CLUSTER_TIMEOUT),
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("Failed to run Rust binary {:?}", rust_bin))?;
|
||||
|
||||
let json_str = std::fs::read_to_string(output_path)
|
||||
.context("Failed to read FACE_CLUSTER output")?;
|
||||
let result: FaceClusterResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse FACE_CLUSTER output")?;
|
||||
tracing::info!(
|
||||
"[FACE_CLUSTER] Rust Result: {} clusters, {} frames",
|
||||
result.clusters.len(),
|
||||
result.frames.len()
|
||||
);
|
||||
return Ok(result);
|
||||
// Try Rust binary first (preferred), fallback to Python if unavailable
|
||||
if let Some(rust_bin) = executor.rust_binary_path("rust_face_cluster") {
|
||||
tracing::info!("[FACE_CLUSTER] Using Rust binary: {:?}", rust_bin);
|
||||
match executor
|
||||
.run_rust_with_output_idx_and_frames(
|
||||
&rust_bin,
|
||||
&args,
|
||||
Some(1),
|
||||
uuid,
|
||||
frames,
|
||||
"FACE_CLUSTER",
|
||||
Some(FACE_CLUSTER_TIMEOUT),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
let json_str = std::fs::read_to_string(output_path)
|
||||
.context("Failed to read FACE_CLUSTER output")?;
|
||||
let result: FaceClusterResult =
|
||||
serde_json::from_str(&json_str).context("Failed to parse FACE_CLUSTER output")?;
|
||||
tracing::info!(
|
||||
"[FACE_CLUSTER] Rust Result: {} clusters, {} frames",
|
||||
result.clusters.len(),
|
||||
result.frames.len()
|
||||
);
|
||||
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
|
||||
.run_with_output_idx_and_frames(
|
||||
"fast_face_clustering_processor.py",
|
||||
|
||||
Reference in New Issue
Block a user