mirror of
https://github.com/pykeio/ort
synced 2026-04-25 16:34:55 +02:00
27 lines
1.3 KiB
Plaintext
27 lines
1.3 KiB
Plaintext
---
|
|
title: WebAssembly
|
|
description: Deploy ONNX models to the web
|
|
---
|
|
|
|
WebAssembly support in `ort` is currently experimental. If you experience any issues using `ort` in WebAssembly, please [open an issue](https://github.com/pykeio/ort/issues/new).
|
|
|
|
By nature, some features of ONNX Runtime are not available in the web. These include:
|
|
- **Support for `.onnx` models.** You instead need to [convert `.onnx` models to the `.ort` format](https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html).
|
|
- **Runtime graph optimizations**, aka `SessionBuilder::with_optimization_level`. You can statically optimize the graph using the `.ort` conversion tool, though.
|
|
- **Loading models with `commit_from_file`/`commit_from_url`.** You can create models from a slice of bytes in memory with `SessionBuilder::commit_from_memory` or `SessionBuilder::commit_from_memory_directly`.
|
|
|
|
Additionally, you'll need to call `ort::wasm::initialize()` at the earliest possible point in your code, before you use any `ort` APIs:
|
|
```rust filename="main.rs" copy
|
|
use ort::Session;
|
|
|
|
static MODEL_BYTES: &[u8] = include_bytes!("../model.ort");
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
#[cfg(target_arch = "wasm32")]
|
|
ort::wasm::initialize();
|
|
|
|
let session = Session::builder()?.commit_from_memory_directly(MODEL_BYTES)?;
|
|
...
|
|
}
|
|
```
|