| Name | Message | Date |
|---|---|---|
| 📄 database.rs | 2 days ago | |
| 📄 exhaustive_matcher.rs | 2 days ago | |
| 📄 feature_extractor.rs | 2 days ago | |
| 📄 main.rs | 2 days ago | |
| 📄 models.rs | 2 days ago | |
| 📄 ransac.rs | 2 days ago |
📄
src/models.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::path::Path; use anyhow::{Context, Result, anyhow}; use ort::ep::{self, ExecutionProvider}; use ort::session::{Session, SessionOutputs}; #[derive(Debug, Clone, Copy, clap::ValueEnum, PartialEq, Eq)] #[value(rename_all = "UPPER")] pub enum Device { Cpu, Gpu, } impl Device { fn openvino_device_type(self) -> &'static str { match self { Device::Cpu => "CPU", Device::Gpu => "GPU", } } } /// Loads an ONNX model with the OpenVINO execution provider targeting `device`. /// Registration failures (e.g. no Arc GPU present) are logged and the session /// silently falls back to the CPU execution provider, per `ort`'s default behavior. pub fn load_session(model_path: &Path, device: Device) -> Result<Session> { let openvino = ep::OpenVINO::default().with_device_type(device.openvino_device_type()); match openvino.is_available() { Ok(true) => {} Ok(false) => eprintln!( "OpenVINO execution provider not available; falling back to CPU for {}", model_path.display() ), Err(e) => eprintln!("Could not query OpenVINO EP availability: {e}"), } Session::builder()? // `.with_execution_providers` returns an error type that carries the SessionBuilder // (for `.recover()`), which holds raw FFI pointers and so isn't Send+Sync; anyhow // requires Send+Sync, so convert explicitly instead of using `?` directly. .with_execution_providers([openvino.build()]) .map_err(|e| anyhow!("{e}"))? .commit_from_file(model_path) .with_context(|| format!("loading ONNX model from {}", model_path.display())) } /// Builds a descriptive error when an expected named output is missing from a model's /// results, listing what output names the model actually produced. pub fn missing_output_err(name: &str, outputs: &SessionOutputs) -> anyhow::Error { anyhow!( "model has no '{name}' output; available outputs: {:?}", outputs.keys().collect::<Vec<_>>() ) }