Skip to content

Commit

Permalink
fix: image layout
Browse files Browse the repository at this point in the history
Signed-off-by: ye jianbai <[email protected]>
  • Loading branch information
ye jianbai committed Mar 3, 2023
1 parent 2445227 commit cd40779
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tf-mobilenet-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ The `tf` model is located at `./frozen.pb`
If you want to generate the [raw](birdx224x224x3.rgb) tensor, you can run:

```shell
cd rust/image-converter/ && cargo run ../../bird.jpg ../../birdx224x224x3.rgb
cd rust/image-converter/ && cargo run ../../PurpleGallinule.jpg ../../birdX224X224X3.rgb && cd ../..
```

### Execute

Execute the WASM with the `wasmedge` with Tensorflow Lite supporting:

```bash
wasmedge --dir .:. wasmedge-wasinn-example-tf-mobilenet-image.wasm saved_model.pb bird.jpg
wasmedge --dir .:. wasmedge-wasinn-example-tf-mobilenet-image.wasm saved_model.pb PurpleGallinule.jpg
```

You will get the output:
Expand Down
Binary file modified tf-mobilenet-image/birdX224X224X3.rgb
Binary file not shown.
8 changes: 4 additions & 4 deletions tf-mobilenet-image/rust/image-converter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
image::imageops::resize(&img, height, width, ::image::imageops::FilterType::Triangle);
let mut flat_img: Vec<f32> = Vec::new();
for rgb in resized.pixels() {
flat_img.push(rgb[0] as f32 / 255.);
flat_img.push(rgb[1] as f32 / 255.);
flat_img.push(rgb[2] as f32 / 255.);
flat_img.push(rgb[0] as f32 / 255.0);
flat_img.push(rgb[1] as f32 / 255.0);
flat_img.push(rgb[2] as f32 / 255.0);
}
let bytes_required = flat_img.len() * 4;
let mut u8_f32_arr: Vec<u8> = vec![0; bytes_required];
Expand All @@ -40,7 +40,7 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
let u8_bytes = u8_f32.to_ne_bytes();

for j in 0..4 {
u8_f32_arr[((flat_img.len() / 3 * c + i) * 4) + j] = u8_bytes[j];
u8_f32_arr[((i * 3 + c) * 4) + j] = u8_bytes[j];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tf-mobilenet-image/rust/tf-mobilenet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
let u8_bytes = u8_f32.to_ne_bytes();

for j in 0..4 {
u8_f32_arr[((flat_img.len() / 3 * c + i) * 4) + j] = u8_bytes[j];
u8_f32_arr[((i * 3 + c) * 4) + j] = u8_bytes[j];
}
}
}
Expand Down
Binary file not shown.

0 comments on commit cd40779

Please sign in to comment.