Fix build errors: ort error Send/Sync bound, ndarray version unification, inputs! macro

Verified with cargo check.
This commit is contained in:
2026-08-28 17:09:15 +00:00
parent 17f8e4b487
commit 94b827613d
4 changed files with 19 additions and 24 deletions
+13 -5
View File
@@ -31,10 +31,18 @@ pub struct FailureDetector {
impl FailureDetector {
pub fn load(model_path: &str, input_size: u32, confidence_threshold: f32, intra_threads: usize) -> anyhow::Result<Arc<Self>> {
let session = Session::builder()?
.with_optimization_level(GraphOptimizationLevel::Level3)?
.with_intra_threads(intra_threads)?
.commit_from_file(model_path)?;
// ort's builder error types carry raw FFI pointers that aren't
// Send/Sync, so they can't flow through `?` into `anyhow::Result`
// directly (anyhow requires Send + Sync + 'static). Stringify at
// the boundary instead.
let session = Session::builder()
.map_err(|e| anyhow::anyhow!("failed to create ONNX Runtime session builder: {e}"))?
.with_optimization_level(GraphOptimizationLevel::Level3)
.map_err(|e| anyhow::anyhow!("failed to set graph optimization level: {e}"))?
.with_intra_threads(intra_threads)
.map_err(|e| anyhow::anyhow!("failed to set intra-op thread count: {e}"))?
.commit_from_file(model_path)
.map_err(|e| anyhow::anyhow!("failed to load ONNX model at {model_path}: {e}"))?;
Ok(Arc::new(Self {
session: Mutex::new(session),
@@ -50,7 +58,7 @@ impl FailureDetector {
let input = Value::from_array(tensor)?;
let mut session = self.session.lock().await;
let outputs = session.run(ort::inputs!["images" => input]?)?;
let outputs = session.run(ort::inputs!["images" => input])?;
// Exported with NMS baked into the graph: output0 is [1, N, 6]
// rows of (x1, y1, x2, y2, confidence, class_id) in input-pixel space.
+1 -5
View File
@@ -1,4 +1,4 @@
use image::{DynamicImage, GenericImageView};
use image::DynamicImage;
use ndarray::Array4;
/// Resizes an RGB frame to a square `size x size` input tensor in CHW layout,
@@ -18,7 +18,3 @@ pub fn to_input_tensor(image: &DynamicImage, size: u32) -> Array4<f32> {
tensor
}
pub fn frame_dimensions(image: &DynamicImage) -> (u32, u32) {
image.dimensions()
}
+3 -13
View File
@@ -132,18 +132,8 @@ async fn process_entry(
Ok(())
}
/// Loads `.env` if present; a missing file is fine (env vars may already be
/// set by the process supervisor), so the error is deliberately ignored.
fn dotenvy_load() {
if let Ok(contents) = std::fs::read_to_string(".env") {
for line in contents.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
continue;
}
if let Some((key, value)) = line.split_once('=') {
if std::env::var(key).is_err() {
std::env::set_var(key, value);
}
}
}
}
let _ = dotenvy::dotenv();
}