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日

#47WebAssembly

Download history 4568/week @ 2024-04-23 4223/week @ 2024-04-30 3963/week @ 2024-05-07 9855/week @ 2024-05-14 6858/week @ 2024-05-21 10110/week @ 2024-05-28 7584/week @ 2024-06-04 12274/week @ 2024-06-11 11362/week @ 2024-06-18 12620/week @ 2024-06-25 8276/week @ 2024-07-02 9665/week @ 2024-07-09 11945/week @ 2024-07-16 13797/week @ 2024-07-23 13760/week @ 2024-07-30 14315/week @ 2024-08-06

每月下载量55,490
用于 2 crates

Apache-2.0

37KB
896

为Rust提供的wasi-nn绑定

此包包含对wasi-nn系统调用的Rust高级绑定。它在目的上与WASI绑定相似,但此包提供从WebAssembly访问系统机器学习功能的可选方式。

注意:这些绑定是实验性的(自行承担风险)并且受wasi-nn规范上游更改的影响。

使用

  1. 在您的Cargo.toml中依赖此crate

    [dependencies]
    wasi-nn = "0.6.0"
    
  2. 在您的应用程序中使用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)?;
    
  3. 将应用程序编译为WebAssembly

    cargo build --target=wasm32-wasi
    
  4. 在支持wasi-nn的运行时中运行生成的WebAssembly,例如Wasmtime

构建

要从源代码构建此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