-
-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathmodel-info.rs
More file actions
53 lines (44 loc) · 1.3 KB
/
model-info.rs
File metadata and controls
53 lines (44 loc) · 1.3 KB
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
use std::{env, process};
use ort::session::Session;
// Include common code for `ort` examples that allows using the various feature flags to enable different EPs and
// backends.
#[path = "../common/mod.rs"]
mod common;
fn main() -> ort::Result<()> {
// Register backends based on feature flags - this isn't crucial for usage and can be removed.
common::init()?;
let Some(path) = env::args().nth(1) else {
eprintln!("usage: ./model-info <model>.onnx");
process::exit(0);
};
let session = Session::builder()?.commit_from_file(path)?;
let meta = session.metadata()?;
if let Some(x) = meta.name() {
println!("Name: {x}");
}
if let Some(x) = meta.description() {
println!("Description: {x}");
}
if let Some(x) = meta.producer() {
println!("Produced by {x}");
}
if let Ok(custom_keys) = meta.custom_keys()
&& !custom_keys.is_empty()
{
println!("=== Custom keys ===");
for key in custom_keys {
if let Some(value) = meta.custom(&key) {
println!(" {key}: {value}");
}
}
};
println!("=== Inputs ===");
for (i, input) in session.inputs().iter().enumerate() {
println!(" {i} {}: {}", input.name(), input.dtype());
}
println!("=== Outputs ===");
for (i, output) in session.outputs().iter().enumerate() {
println!(" {i} {}: {}", output.name(), output.dtype());
}
Ok(())
}