Skip to main content

inspect_model/
inspect_model.rs

1//! Inspect a CoreML model's inputs, outputs, and metadata.
2//!
3//! Usage: cargo run --example inspect_model -- <path/to/model.mlmodelc>
4
5use coreml_native::{ComputeUnits, Model};
6
7fn main() {
8    let model_path = std::env::args()
9        .nth(1)
10        .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12    println!("Loading model: {model_path}");
13    let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15    println!("\n--- Inputs ---");
16    for desc in model.inputs() {
17        println!(
18            "  {}: {:?} shape={:?} optional={}",
19            desc.name(),
20            desc.feature_type(),
21            desc.shape(),
22            desc.is_optional(),
23        );
24        if let Some(dt) = desc.data_type() {
25            println!("    data_type: {dt}");
26        }
27    }
28
29    println!("\n--- Outputs ---");
30    for desc in model.outputs() {
31        println!(
32            "  {}: {:?} shape={:?}",
33            desc.name(),
34            desc.feature_type(),
35            desc.shape(),
36        );
37        if let Some(dt) = desc.data_type() {
38            println!("    data_type: {dt}");
39        }
40    }
41
42    let meta = model.metadata();
43    println!("\n--- Metadata ---");
44    println!("  author: {:?}", meta.author);
45    println!("  description: {:?}", meta.description);
46    println!("  version: {:?}", meta.version);
47    println!("  license: {:?}", meta.license);
48}