A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
This example project demonstrates using the wasi-nn API to perform WinML-based
inference. We first build Wasmtime, a fast and secure runtime for WebAssembly,
and then build a WebAssembly example, which:
- reads an input image from
fixture/kitten.png, - converts it to the correct tensor format,
- and then classifies the image using
fixture/mobilenet.onnx
To run this example, perform the following steps on Windows 10 v1803 and later:
- Build Wasmtime according to the build guide, but enable the
winmlfeature:cargo build --release --features wasmtime-wasi-nn/winml - Navigate to this directory from Wasmtime's top-level directory (referred to
later as `%PROJECT_DIR%).
set PROJECT_DIR=%CD% cd crates\wasi-nn\examples\classification-example-winml - Install the
wasm32-wasip1Rust target:rustup target add wasm32-wasip1 - Compile this example; the
wasm32-wasip1output is a WebAssembly file:cargo build --release --target=wasm32-wasip1 - Run the sample; the fixture directory containing the model and image must be
mapped in to be accessible to WebAssembly.
%PROJECT_DIR%\target\release\wasmtime.exe --dir fixture::fixture -S nn target\wasm32-wasip1\release\wasi-nn-example-winml.wasm - The example will print the top 5 classification results. To run with a
different image or ONNX model, modify the files in the
fixturedirectory along with any path changes this may causesrc/main.rs.