The checked-in examples demonstrate the .webnn DSL, raw-weight utilities, JavaScript emitter, and interactive
HTML emitter.
For format details, see:
format_reference.webnnexercises the maintained v2 grammar and is covered by a round-trip test.resnet_head.webnnis a small graph whose constants use external references.tensors/contains tensor metadata. The build script reconstructs untracked raw.bininputs from the checked-in reference archive.build_example.shcreates a manifest, packs aWGWTweights file, and emits JavaScript.browser_example.htmlis an example host for emitted WebNN builder code.
Some generated artifacts are checked in for inspection. Rerun the script before relying on them after changing the graph, manifest, tensors, or emitter.
cargo run -- parse examples/format_reference.webnn > /tmp/format_reference.json
cargo run -- serialize /tmp/format_reference.json > /tmp/format_reference.webnn
cargo run -- validate /tmp/format_reference.webnnThe format-reference graph declares an external tensor for syntax coverage. Parsing and structural validation do not resolve that sidecar.
Run the complete ResNet-head example from the repository root:
./examples/build_example.shIt performs the equivalent steps:
cargo run -- create-manifest \
--input-dir examples/tensors \
--output examples/resnet_head.manifest.json \
--endianness little
cargo run -- pack-weights \
--manifest examples/resnet_head.manifest.json \
--input-dir examples/tensors \
--output examples/resnet_head.weights
cargo run -- validate examples/resnet_head.webnn \
--weights-manifest examples/resnet_head.manifest.json
cargo run -- emit-js examples/resnet_head.webnn > examples/buildGraph.jsThe packed file begins with the WGWT version-1 header. Manifest byte offsets are absolute from the beginning
of that file, including its eight-byte header.
Inspect the archive by unpacking it into a temporary directory:
cargo run -- unpack-weights \
--weights examples/resnet_head.weights \
--manifest examples/resnet_head.manifest.json \
--output-dir /tmp/resnet_head_tensorsGenerate WebNN builder JavaScript:
cargo run -- emit-js examples/resnet_head.webnn > /tmp/build_graph.jsGenerate a standalone graph visualization:
cargo run -- emit-html examples/resnet_head.webnn > /tmp/resnet_head.htmlExecuting the generated builder requires a JavaScript environment that implements the WebNN APIs used by the graph. The emitters do not provide a WebNN runtime.
ONNX conversion is available with the default onnx feature:
cargo run -- convert-onnx \
--input model.onnx \
--output model.webnn \
--weights model.weights \
--manifest model.manifest.json \
--override-dim batch_size=1 \
--optimizeSee ONNX to WebNN lowering and Dynamic dimensions for current conversion behavior.