7个版本 (破坏性)
0.6.0 | 2023年8月25日 |
---|---|
0.5.0 | 2023年8月15日 |
0.4.0 | 2023年6月23日 |
0.3.0 | 2023年3月13日 |
0.1.0 | 2021年4月12日 |
#47 在 WebAssembly
每月下载量55,490
用于 2 crates
37KB
896 行
为Rust提供的wasi-nn绑定
此包包含对wasi-nn系统调用的Rust高级绑定。它在目的上与WASI绑定相似,但此包提供从WebAssembly访问系统机器学习功能的可选方式。
注意:这些绑定是实验性的(自行承担风险)并且受wasi-nn规范上游更改的影响。
使用
-
在您的
Cargo.toml
中依赖此crate[dependencies] wasi-nn = "0.6.0"
-
在您的应用程序中使用wasi-nn API,例如
use wasi_nn; let graph = GraphBuilder::new(GraphEncoding::TensorflowLite, ExecutionTarget::CPU) .build_from_files([model_path])?; let mut ctx = graph.init_execution_context()?; ctx.set_input(0, TensorType::F32, &input_dims, &input_buffer)?; ctx.compute()?; let output_num_bytes = ctx.get_output(0, &mut output_buffer)?;
-
将应用程序编译为WebAssembly
cargo build --target=wasm32-wasi
构建
要从源代码构建此crate,使用:cargo build --target wasm32-wasi
.
生成
此crate包含由witx-bindgen
生成的代码 (src/generated.rs
)。要重新生成此代码,运行以下脚本
$ scripts/regenerate-bindings-from-witx.sh
示例
示例演示了如何从Rust程序中使用wasi-nn。
许可
本项目采用Apache 2.0许可证。有关详细信息,请参阅LICENSE。
贡献
除非您明确说明,否则您提交的任何有意包含在此项目中的贡献(根据Apache-2.0许可证定义),均应按上述方式许可,不附加任何额外条款或条件。
依赖项
~310–780KB
~18K SLoC