@@ -89,24 +89,37 @@ browser deals with image or video encoding.
89
89
90
90
### Non-goals
91
91
92
- wasi-nn is not designed to provide support for individual ML operations (a "model builder" API). The
93
- ML field is still evolving rapidly, with new operations and network topologies emerging
92
+ ` wasi-nn ` is not designed to provide support for individual ML operations (a "model builder" API).
93
+ The ML field is still evolving rapidly, with new operations and network topologies emerging
94
94
continuously. It would be a challenge to define an evolving set of operations to support in the API.
95
95
Instead, our approach is to start with a "model loader" API, inspired by WebNN’s model loader
96
96
proposal.
97
97
98
98
### API walk-through
99
99
100
- The following example describes how a user would use ` wasi-nn ` to classify an image.
100
+ The following example describes how a user would use ` wasi-nn ` :
101
101
102
- ```
103
- TODO
102
+ ``` rust
103
+ // Load the model.
104
+ let encoding = wasi_nn :: GRAPH_ENCODING_ ... ;
105
+ let target = wasi_nn :: EXECUTION_TARGET_CPU ;
106
+ let graph = wasi_nn :: load (& [bytes , more_bytes ], encoding , target );
107
+
108
+ // Configure the execution context.
109
+ let context = wasi_nn :: init_execution_context (graph );
110
+ let tensor = wasi_nn :: Tensor { ... };
111
+ wasi_nn :: set_input (context , 0 , tensor );
112
+
113
+ // Compute the inference.
114
+ wasi_nn :: compute (context );
115
+ wasi_nn :: get_output (context , 0 , & mut output_buffer , output_buffer . len ());
104
116
```
105
117
106
- <!--
107
- More use cases go here: provide example code snippets and diagrams explaining how the API would be
108
- used to solve the given problem.
109
- -->
118
+ Note that the details above will depend on the model and backend used; the pseudo-Rust simply
119
+ illustrates the general idea, minus any error-checking. Consult the
120
+ [ AssemblyScript] ( https://github.com/bytecodealliance/wasi-nn/tree/main/assemblyscript/examples ) and
121
+ [ Rust] ( https://github.com/bytecodealliance/wasi-nn/tree/main/rust/examples ) bindings for more
122
+ detailed examples.
110
123
111
124
### Detailed design discussion
112
125
0 commit comments