Skip to content

Commit c975f20

Browse files
authored
Fix deleted WasmEdge tensorflow plug-in. (#159)
Signed-off-by: YiYing He <yiying@secondstate.io>
1 parent 1c902c4 commit c975f20

File tree

29 files changed

+475
-425
lines changed

29 files changed

+475
-425
lines changed

docs/develop/rust/wasinn/mediapipe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ DetectionResult:
6363

6464
## Understand the code
6565

66-
The [main.rs](https://github.com/juntao/demo-object-detection/blob/main/src/main.rs) is the complete example Rust source.
66+
The [main.rs](https://github.com/juntao/demo-object-detection/blob/main/src/main.rs) is the complete example Rust source.
6767
All `mediapipe-rs` APIs follow a common pattern. A Rust struct is designed to work with a model. It contains functions
6868
required to pre- and post-process data for the model. For example, we can create an `detector` instance
6969
using the builder pattern, which can build from any "object detection" model in the Mediapipe model library.

docs/develop/rust/wasinn/pytorch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ wasmedge --dir .:. out.wasm mobilenet.pt input.jpg
7474

7575
## Understand the code
7676

77-
The [main.rs](https://github.com/second-state/WasmEdge-WASINN-examples/tree/master/pytorch-mobilenet-image/rust/src/main.rs) is the complete example Rust source. First, read the image file and PyTorch model file names from the command line.
77+
The [main.rs](https://github.com/second-state/WasmEdge-WASINN-examples/tree/master/pytorch-mobilenet-image/rust/src/main.rs) is the complete example Rust source. First, read the image file and PyTorch model file names from the command line.
7878

7979
```rust
8080
let args: Vec<String> = env::args().collect();

docs/develop/rust/wasinn/tensorflow_lite.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ wasmedge --dir .:. out.wasm lite-model_aiy_vision_classifier_birds_V1_3.tflite b
7474

7575
## Understand the code
7676

77-
The [main.rs](https://github.com/second-state/WasmEdge-WASINN-examples/blob/master/tflite-birds_v1-image/rust/tflite-bird/src/main.rs) is the complete example Rust source. First, read the image file and Tensorflow Lite (tflite) model file names from the command line.
77+
The [main.rs](https://github.com/second-state/WasmEdge-WASINN-examples/blob/master/tflite-birds_v1-image/rust/tflite-bird/src/main.rs) is the complete example Rust source. First, read the image file and Tensorflow Lite (tflite) model file names from the command line.
7878

7979
```rust
8080
let args: Vec<String> = env::args().collect();
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 5
33
---
44

5-
# TensorFlow Interface
5+
# TensorFlow Plug-in For WasmEdge
66

7-
Developers can use [WASI-NN](/category/neural-networks-for-wasi) to inference the models. However, for the TensorFlow and TensorFlow-Lite users, the WASI-NN APIs could be more friendly to retrieve the input and output tensors. Therefore WasmEdge provides the TensorFlow-related plug-in and rust SDK for inferencing models in WASM.
7+
Developers can use [WASI-NN](https://github.com/WebAssembly/wasi-nn) to inference the models. However, for the TensorFlow and TensorFlow-Lite users, the WASI-NN APIs could be more friendly to retrieve the input and output tensors. Therefore WasmEdge provides the TensorFlow-related plug-in and rust SDK for inferencing models in WASM.
8+
9+
<!-- prettier-ignore -->
10+
:::info
11+
This is not a WASI-NN compatible plug-in. If you are finding the plug-ins working with the [WASI-NN crate](https://crates.io/crates/wasi-nn), please follow the [tensorflow-lite backend](tensorflow_lite.md) instead.
12+
:::
813

914
## Prerequisite
1015

11-
Please ensure that you [Rust and WasmEdge installed](setup.md).
16+
Please ensure that you [Rust and WasmEdge installed](../setup.md).
1217

1318
Developers will add the [`wasmedge_tensorflow_interface` crate](https://crates.io/crates/wasmedge_tensorflow_interface) as a dependency to their `Rust -> Wasm` applications. For example, add the following line to the application's `Cargo.toml` file.
1419

@@ -27,7 +32,7 @@ use wasmedge_tensorflow_interface;
2732

2833
In this crate, we provide several functions to decode and convert images into tensors using the `WasmEdge-Image` host functions.
2934

30-
To use these functions in WASM and execute in WasmEdge, users should [install WasmEdge with WasmEdge-Image plug-in](../../start/install.md#wasmedge-image-plug-in).
35+
To use these functions in WASM and execute in WasmEdge, users should [install WasmEdge with WasmEdge-Image plug-in](../../../start/install.md#wasmedge-image-plug-in).
3136

3237
For decoding the `JPEG` images, there are:
3338

@@ -67,9 +72,9 @@ let flat_img = wasmedge_tensorflow_interface::load_jpg_image_to_rgb32f(&img_buf,
6772

6873
## Inferring TensorFlow And TensorFlow-Lite Models
6974

70-
For using the `TFSession` struct to inference the TensorFlow models and executing in WasmEdge, users should install the [WasmEdge-TensorFlow plug-in with dependencies](../../start/install.md#wasmedge-tensorflow-plug-in).
75+
For using the `TFSession` struct to inference the TensorFlow models and executing in WasmEdge, users should install the [WasmEdge-TensorFlow plug-in with dependencies](../../../start/install.md#wasmedge-tensorflow-plug-in).
7176

72-
For using the `TFLiteSession` struct and to inference the TensorFlow-Lite models executing in WasmEdge, users should install the [WasmEdge-TensorFlowLite plug-in with dependencies](../../start/install.md#wasmedge-tensorflow-lite-plug-in).
77+
For using the `TFLiteSession` struct and to inference the TensorFlow-Lite models executing in WasmEdge, users should install the [WasmEdge-TensorFlowLite plug-in with dependencies](../../../start/install.md#wasmedge-tensorflow-lite-plug-in).
7378

7479
### Create Session
7580

@@ -125,7 +130,7 @@ cargo build --target=wasm32-wasi
125130

126131
The output WASM file will be at `target/wasm32-wasi/debug/` or `target/wasm32-wasi/release`.
127132

128-
Please refer to [WasmEdge CLI](../../start/build-and-run/cli.md) for WASM execution.
133+
Please refer to [WasmEdge CLI](../../../start/build-and-run/cli.md) for WASM execution.
129134

130135
## Examples
131136

docs/embed/go/ai.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,23 @@ sidebar_position: 5
99
The WasmEdge extensions have been deprecated after the v0.12.1 version. We'll update to use the WasmEdge plug-in in the future.
1010
:::
1111

12-
In this section, we will show you how to create a TensorFlow inference function in Rust for image classification and then embed it into a Go application. The project source code is [available here](https://github.com/second-state/WasmEdge-go-examples/tree/master/wasmedge-bindgen/go_TfliteFood).
12+
In this section, we will show you how to create a TensorFlow or TensorFlow-Lite inference function in Rust for image classification and then embed it into a Go application. The project source code is [available here](https://github.com/second-state/WasmEdge-go-examples/blob/master/go_TfliteFood/).
1313

1414
## The WASM app in Rust
1515

16-
The Rust function for image classification is [available here](https://github.com/second-state/WasmEdge-go-examples/blob/master/wasmedge-bindgen/go_TfliteFood/rust_tflite_food/src/lib.rs). It utilizes the WasmEdge Tensorflow Lite plug-in as well as the [wasmedge_bindgen](function.md) for passing call parameters.
16+
The Rust function for image classification is [available here](https://github.com/second-state/WasmEdge-go-examples/blob/master/go_TfliteFood/rust_tflite_food/src/lib.rs). It utilizes the WasmEdge Tensorflow Lite plug-in as well as the [wasmedge_bindgen](function.md) for passing call parameters.
1717

1818
```rust
1919
#[wasmedge_bindgen]
2020
fn infer(image_data: Vec<u8>) -> Result<Vec<u8>, String> {
21-
... ...
21+
let img = image::load_from_memory(&image_data).unwrap().to_rgb8();
2222
let flat_img = image::imageops::thumbnail(&img, 192, 192);
2323

2424
let model_data: &[u8] = include_bytes!("lite-model_aiy_vision_classifier_food_V1_1.tflite");
2525
let labels = include_str!("aiy_food_V1_labelmap.txt");
2626

27-
let mut session = wasmedge_tensorflow_interface::Session::new(
28-
model_data,
29-
wasmedge_tensorflow_interface::ModelType::TensorFlowLite,
30-
);
31-
session
32-
.add_input("input", &flat_img, &[1, 192, 192, 3])
33-
.run();
27+
let mut session = wasmedge_tensorflow_interface::TFLiteSession::new(model_data);
28+
session.add_input("input", &flat_img).run();
3429
let res_vec: Vec<u8> = session.get_output("MobilenetV1/Predictions/Softmax");
3530
... ...
3631
}
@@ -42,7 +37,7 @@ You can build the standard `Cargo` command into a WebAssembly function.
4237

4338
```bash
4439
git clone https://github.com/second-state/WasmEdge-go-examples.git
45-
cd rust_tflite_food
40+
cd go_TfliteFood/rust_tflite_food
4641
cargo build --target wasm32-wasi --release
4742
cp target/wasm32-wasi/release/rust_tflite_food_lib.wasm ../
4843
cd ../
@@ -56,54 +51,66 @@ wasmedge compile rust_tflite_food_lib.wasm rust_tflite_food_lib.wasm
5651

5752
## Go host app
5853

59-
The [Go host app](https://github.com/second-state/WasmEdge-go-examples/blob/master/wasmedge-bindgen/go_TfliteFood/tflite_food.go) source code shows how to instantiate a WasmEdge runtime with the Tensorflow extension, and how to pass the image data to the Rust function in WasmEdge to run the inference.
54+
The [Go host app](https://github.com/second-state/WasmEdge-go-examples/blob/master/go_TfliteFood/tflite_food.go) source code shows how to instantiate a WasmEdge runtime with the Tensorflow extension, and how to pass the image data to the Rust function in WasmEdge to run the inference.
6055

6156
```go
57+
import (
58+
"fmt"
59+
"io/ioutil"
60+
"os"
61+
62+
"github.com/second-state/WasmEdge-go/wasmedge"
63+
bindgen "github.com/second-state/wasmedge-bindgen/host/go"
64+
)
65+
6266
func main() {
63-
// Expected Args[0]: program name (./tflite_food)
64-
// Expected Args[1]: wasm file (rust_tflite_food_lib.wasm)
65-
// Expected Args[2]: input image name (food.jpg)
67+
fmt.Println("Go: Args:", os.Args)
68+
// Expected Args[0]: program name (./mobilenet)
69+
// Expected Args[1]: wasm file (rust_mobilenet_lib.wasm)
70+
// Expected Args[2]: input image name (grace_hopper.jpg)
6671

72+
// Set not to print debug info
6773
wasmedge.SetLogErrorLevel()
6874

6975
// Set Tensorflow not to print debug info
7076
os.Setenv("TF_CPP_MIN_LOG_LEVEL", "3")
7177
os.Setenv("TF_CPP_MIN_VLOG_LEVEL", "3")
7278

79+
// Load WasmEdge-image and WasmEdge-tensorflow from default path
80+
wasmedge.LoadPluginDefaultPaths()
81+
82+
// Create configure
7383
var conf = wasmedge.NewConfigure(wasmedge.WASI)
84+
85+
// Create VM with configure
7486
var vm = wasmedge.NewVMWithConfig(conf)
87+
88+
// Init WASI
7589
var wasi = vm.GetImportModule(wasmedge.WASI)
7690
wasi.InitWasi(
7791
os.Args[1:], // The args
7892
os.Environ(), // The envs
7993
[]string{".:."}, // The mapping preopens
8094
)
8195

82-
// Register WasmEdge-tensorflow
83-
var tfmod = wasmedge.NewTensorflowModule()
84-
var tflitemod = wasmedge.NewTensorflowLiteModule()
85-
vm.RegisterModule(tfmod)
86-
vm.RegisterModule(tflitemod)
87-
8896
// Load and validate the wasm
8997
vm.LoadWasmFile(os.Args[1])
9098
vm.Validate()
9199

92100
// Instantiate the bindgen and vm
93-
bg := bindgen.Instantiate(vm)
101+
bg := bindgen.New(vm)
102+
bg.Instantiate()
94103

95104
img, _ := ioutil.ReadFile(os.Args[2])
96-
if res, err := bg.Execute("infer", img); err != nil {
105+
if res, _, err := bg.Execute("infer", img); err != nil {
97106
fmt.Println(err)
98107
} else {
99-
fmt.Println(string(res))
108+
fmt.Println(res[0].(string))
100109
}
101110

102111
bg.Release()
103112
vm.Release()
104113
conf.Release()
105-
tfmod.Release()
106-
tflitemod.Release()
107114
}
108115
```
109116

@@ -114,10 +121,10 @@ func main() {
114121
Ensure you have installed [Go, WasmEdge, and WasmEdge Go SDK with the TensorFlow extension](intro.md).
115122
:::
116123

117-
The following command builds the Go host application with the WasmEdge Go SDK and its TensorFlow extension.
124+
Builds the Go host application with the WasmEdge Go SDK.
118125

119126
```bash
120-
go build -tags tensorflow
127+
go build
121128
```
122129

123130
Now you can run the Go application. It calls the WebAssembly function in WasmEdge to run inference on the input image.

docs/embed/go/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ go build
3434

3535
<!-- prettier-ignore -->
3636
:::note
37-
The WasmEdge extensions have been deprecated after the 0.12.1 version. We'll update to use the WasmEdge plug-in in the future.
37+
The WasmEdge extensions have been deprecated after the 0.12.1 version. Please use the corresponding plug-ins after the 0.13.0 version.
3838
:::
3939

4040
By default, the `WasmEdge-go` only turns on the basic runtime.

docs/start/install.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@ Then, go to [WASI-Crypto in Rust chapter](../develop/rust/wasicrypto.md) to see
217217

218218
The wasmEdge-Image plug-in can help developers to load and decode JPEG and PNG images and convert into tensors. To install this plug-in, please use the `--plugins wasmedge_image` parameter when [running the installer command](#generic-linux-and-macos).
219219

220+
Then, go to [TensorFlow interface (image part) in Rust chapter](../develop/rust/wasinn/tf_plugin.md#image-loading-and-conversion) to see how to run `WasmEdge-Image` functions.
221+
222+
### WasmEdge TensorFlow Plug-in
223+
224+
WasmEdge-TensorFlow plug-in can help developers to perform `TensorFlow` model inference as the similar API in python. To install this plug-in, please use the `--plugins wasmedge_tensorflow` parameter when [running the installer command](#generic-linux-and-macos).
225+
226+
The WasmEdge-Tensorflow plug-in depends on the `libtensorflow_cc` shared library.
227+
228+
<!-- prettier-ignore -->
229+
:::note
230+
If you install this plug-in WITHOUT installer, you can [refer to here to install the dependency](#tensorflow-dependencies).
231+
:::note
232+
233+
Then, go to [TensorFlow interface in Rust chapter](../develop/rust/wasinn/tf_plugin.md) to see how to run `WasmEdge-TensorFlow` functions.
234+
235+
### WasmEdge TensorFlow-Lite Plug-in
236+
237+
The wasmEdge-TensorFlowLite plug-in can help developers to perform `TensorFlow-Lite` model inference as the similar API in python. To install this plug-in, please use the `--plugins wasmedge_tensorflowlite` parameter when [running the installer command](#generic-linux-and-macos).
238+
239+
The WasmEdge-TensorflowLite plug-in depends on the `libtensorflowlite_c` shared library to perform AI/ML computations, and it will be installed by the installer automatically.
240+
241+
<!-- prettier-ignore -->
242+
:::note
243+
If you install this plug-in WITHOUT installer, you can [refer to here to install the dependency](#tensorflow-lite-dependencies).
244+
:::note
245+
246+
Then, go to [TensorFlow interface in Rust chapter](../develop/rust/wasinn/tf_plugin.md) to see how to run `WasmEdge-TensorFlowLite` functions.
247+
220248
## Install WasmEdge extensions and dependencies
221249

222250
<!-- prettier-ignore -->

i18n/zh/docusaurus-plugin-content-docs/current/contribute/plugin/develop_plugin_cpp.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To create a plug-in with host functions and modules, follow these steps:
6262
```cpp
6363
#pragma once
6464

65-
#include "plug-in/plug-in.h"
65+
#include "plugin/plugin.h"
6666

6767
#include <cstdint>
6868
#include <string>
@@ -228,9 +228,6 @@ To build the plug-in shared library, developers should build in CMake with the W
228228
```cmake
229229
wasmedge_add_library(wasmedgePluginTest
230230
SHARED
231-
env.cpp
232-
func.cpp
233-
module.cpp
234231
testplugin.cpp
235232
)
236233

i18n/zh/docusaurus-plugin-content-docs/current/develop/javascript/hello_world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Then download the pre-built WasmEdge QuickJS Runtime program, and optionally, AO
1919

2020
```bash
2121
curl -OL https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm
22-
wasmedgec wasmedge_quickjs.wasm wasmedge_quickjs.wasm
22+
wasmedge compile wasmedge_quickjs.wasm wasmedge_quickjs.wasm
2323
```
2424

2525
<!-- prettier-ignore -->

i18n/zh/docusaurus-plugin-content-docs/current/develop/javascript/networking.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ The QuickJS WasmEdge Runtime supports Node.js's `http` and `fetch` APIs via the
88

99
The networking API in WasmEdge is non-blocking and hence supports asynchronous I/O-intensive applications. With this API, the JavaScript program can open multiple connections concurrently. It polls those connections or registers async callback functions to process data whenever data comes in, without waiting for any one connection to complete its data transfer. That allows the single-threaded application to handle multiple, multiple concurrent requests.
1010

11-
- [Networking](#networking)
12-
- [Prerequisites](#prerequisites)
13-
- [Fetch client](#fetch-client)
14-
- [HTTP server](#http-server)
15-
- [TCP server and client](#tcp-server-and-client)
11+
- [Prerequisites](#prerequisites)
12+
- [Fetch client](#fetch-client)
13+
- [HTTP server](#http-server)
14+
- [TCP server and client](#tcp-server-and-client)
1615

1716
## Prerequisites
1817

19-
[See here](./hello_world#prerequisites)
18+
[Install WasmEdge](../../start/install.md). To make HTTPS requests, install the [WasmEdge TLS plug-in](../../start/install.md#tls-plug-in).
19+
20+
[Install WasmEdge-QuickJS](./hello_world#prerequisites). Make sure that the `modules` directory is located in your local directory where you want to execute the `wasmedge` command.
2021

2122
## Fetch client
2223

0 commit comments

Comments
 (0)