Name Date Size #Lines LOC

..15-May-2026-

src/H15-May-2026-5435

.gitignoreH A D15-May-202618 32

Cargo.lockH A D15-May-20261.8 KiB7566

Cargo.tomlH A D15-May-2026385 1613

README.mdH A D15-May-20261.8 KiB4331

README.md

1# Named Model Example
2
3This example is mostly the same as the [`classification-example`] but uses
4wasi-nn's "named model" API to load the ML model before the WebAssembly program
5executes. Instead of loading the model bytes during program execution (which may
6be prohibitively slow for large models), this wasi-nn extension allows the model
7to be loaded by the engine prior to execution.
8
9### Pre-requisites
10
11The example pre-requisites are mostly the same as that of the
12[`classification-example`], except that we separate the model files that the
13engine pre-loads (`mobilenet/*`) from the image file read via WASI from the host
14(`fixture/*`):
15
16```
17wget https://download.01.org/openvinotoolkit/fixtures/mobilenet/mobilenet.bin -O mobilenet/model.bin
18wget https://download.01.org/openvinotoolkit/fixtures/mobilenet/mobilenet.xml -O mobilenet/model.xml
19wget https://download.01.org/openvinotoolkit/fixtures/mobilenet/tensor-1x224x224x3-f32.bgr -O fixture/tensor.bgr
20```
21
22As before, this Rust [example] compiles to a WebAssembly program using the
23`wasm32-wasip1` target: `cargo build --target=wasm32-wasip1`.
24
25[example]: src/main.rs
26
27### Run
28
29The program is invoked with slightly different flags than the
30[`classification-example`]:
31
32```
33<path>/<to>/wasmtime run --dir=fixture --wasi=nn --wasi=nn-graph=openvino::mobilenet target/wasm32-wasip1/debug/wasi-nn-example-named.wasm
34```
35
36The primary difference is the addition of `--wasi=nn-graph=openvino::mobilenet`:
37this informs Wasmtime's wasi-nn implementation to pre-load a named model from
38the `mobilenet` directory using the `openvino` encoding. Note that, in this
39implementation, the model name (i.e., `mobilenet`) is derived from the base name
40of the path passed in `--nn-graph=<encoding>::<path>`.
41
42[`classification-example`]: ../classification-example
43