Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openvino-mobilenet-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Please refer to [WasmEdge Docs](https://wasmedge.org/docs/contribute/source/plug
cargo build --target wasm32-wasip1 --release
cd ..

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

If the commands above run successfully, you will get the output:
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion openvino-mobilenet-raw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Please refer to [WasmEdge Docs](https://wasmedge.org/docs/contribute/source/plug
cargo build --target wasm32-wasip1 --release
cd ..

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

If the commands above run successfully, you will get the output:
Expand Down
30 changes: 28 additions & 2 deletions openvino-mobilenet-raw/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,36 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {

// Load a tensor that precisely matches the graph input tensor (see
// `fixture/frozen_inference_graph.xml`).
print!("Set input tensor ...");
print!("Load input tensor ...");
let input_dims = vec![1, 3, 224, 224];
let tensor_data = fs::read(tensor_name).unwrap();
context.set_input(0, TensorType::F32, &input_dims, tensor_data)?;
println!("done");

print!("Transpose input tensor ...");
// Transpose from [height, width, 3] to [3, height, width]
// For the historical reasons, the input tensor is in the format of [height, width, channels],
// but the graph expects it in the format of [channels, height, width].
// The input tensor is 224x224x3, so we need to transpose it
// to 3x224x224.
let height = 224;
let width = 224;
println!("tensor_data.len() = {}", tensor_data.len());
let mut transposed: Vec<u8> = vec![0; tensor_data.len()];
for ch in 0..3 {
for y in 0..height {
for x in 0..width {
let loc = y * height + x;
for b in 0..4 {
transposed[(ch * width * height + loc) * 4 + b as usize] =
tensor_data[(loc * 3 + ch) * 4 + b as usize];
}
}
}
}
println!("done");

print!("Set input tensor ...");
context.set_input(0, TensorType::F32, &input_dims, transposed)?;
println!("done");

print!("Perform graph inference ...");
Expand Down
18 changes: 11 additions & 7 deletions openvino-road-segmentation-adas/openvino-road-seg-adas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
let bytes_required = raw_u8_arr.len() * 4;
let mut u8_f32_arr: Vec<u8> = vec![0; bytes_required];

for i in 0..raw_u8_arr.len() {
// Read the number as a f32 and break it into u8 bytes
let u8_f32: f32 = raw_u8_arr[i] as f32;
let u8_bytes = u8_f32.to_ne_bytes();

for j in 0..4 {
u8_f32_arr[(i * 4) + j] = u8_bytes[j];
// put in NCHW format
let block_size: usize = (height * width) as usize;
for c in 0..3 {
for i in 0..block_size {
// Read the number as a f32 and break it into u8 bytes
let u8_f32: f32 = raw_u8_arr[i * 3 + c] as f32;
let u8_bytes = u8_f32.to_ne_bytes();

for j in 0..4 {
u8_f32_arr[(c * block_size + i) * 4 + j] = u8_bytes[j];
}
}
}
return u8_f32_arr;
Expand Down
Binary file not shown.
55 changes: 22 additions & 33 deletions openvino-road-segmentation-adas/visualize_inference_result.ipynb

Large diffs are not rendered by default.