Skip to content

Commit 6b30ca9

Browse files
committed
fix: update the openvino exmaple
Signed-off-by: Sylveon <[email protected]>
1 parent 1426b10 commit 6b30ca9

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

openvino-mobilenet-image/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Please refer to [WasmEdge Docs](https://wasmedge.org/docs/contribute/source/plug
5757
cargo build --target wasm32-wasip1 --release
5858
cd ..
5959

60-
wasmedge --dir .:. ./rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet.wasm mobilenet.xml mobilenet.bin input.jpg
60+
wasmedge --dir .:. ./rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet-image.wasm mobilenet.xml mobilenet.bin input.jpg
6161
```
6262

6363
If the commands above run successfully, you will get the output:
Binary file not shown.

openvino-mobilenet-raw/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Please refer to [WasmEdge Docs](https://wasmedge.org/docs/contribute/source/plug
5757
cargo build --target wasm32-wasip1 --release
5858
cd ..
5959

60-
wasmedge --dir .:. ./rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet-image.wasm mobilenet.xml mobilenet.bin input.jpg
60+
wasmedge --dir .:. ./rust/target/wasm32-wasip1/release/wasmedge-wasinn-example-mobilenet.wasm mobilenet.xml mobilenet.bin tensor-1x224x224x3-f32.bgr
6161
```
6262

6363
If the commands above run successfully, you will get the output:

openvino-mobilenet-raw/rust/src/main.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,36 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
2222

2323
// Load a tensor that precisely matches the graph input tensor (see
2424
// `fixture/frozen_inference_graph.xml`).
25-
print!("Set input tensor ...");
25+
print!("Load input tensor ...");
2626
let input_dims = vec![1, 3, 224, 224];
2727
let tensor_data = fs::read(tensor_name).unwrap();
28-
context.set_input(0, TensorType::F32, &input_dims, tensor_data)?;
28+
println!("done");
29+
30+
print!("Transpose input tensor ...");
31+
// Transpose from [height, width, 3] to [3, height, width]
32+
// For the historical reasons, the input tensor is in the format of [height, width, channels],
33+
// but the graph expects it in the format of [channels, height, width].
34+
// The input tensor is 224x224x3, so we need to transpose it
35+
// to 3x224x224.
36+
let height = 224;
37+
let width = 224;
38+
println!("tensor_data.len() = {}", tensor_data.len());
39+
let mut transposed: Vec<u8> = vec![0; tensor_data.len()];
40+
for ch in 0..3 {
41+
for y in 0..height {
42+
for x in 0..width {
43+
let loc = y * height + x;
44+
for b in 0..4 {
45+
transposed[(ch * width * height + loc) * 4 + b as usize] =
46+
tensor_data[(loc * 3 + ch) * 4 + b as usize];
47+
}
48+
}
49+
}
50+
}
51+
println!("done");
52+
53+
print!("Set input tensor ...");
54+
context.set_input(0, TensorType::F32, &input_dims, transposed)?;
2955
println!("done");
3056

3157
print!("Perform graph inference ...");

0 commit comments

Comments
 (0)