Skip to content

Commit 115e84d

Browse files
author
ye jianbai
committed
fix: image layout
Signed-off-by: ye jianbai <your_email@abc.example>
1 parent 22f1966 commit 115e84d

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

tf-mobilenet-image/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ The `tf` model is located at `./frozen.pb`
4949
If you want to generate the [raw](birdx224x224x3.rgb) tensor, you can run:
5050

5151
```shell
52-
cd rust/image-converter/ && cargo run ../../bird.jpg ../../birdx224x224x3.rgb
52+
cd rust/image-converter/ && cargo run ../../PurpleGallinule.jpg ../../birdX224X224X3.rgb && cd ../..
5353
```
5454

5555
### Execute
5656

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

5959
```bash
60-
wasmedge --dir .:. wasmedge-wasinn-example-tf-mobilenet-image.wasm saved_model.pb bird.jpg
60+
wasmedge --dir .:. wasmedge-wasinn-example-tf-mobilenet-image.wasm saved_model.pb PurpleGallinule.jpg
6161
```
6262

6363
You will get the output:

tf-mobilenet-image/birdX224X224X3.rgb

0 Bytes
Binary file not shown.

tf-mobilenet-image/rust/image-converter/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
2626
image::imageops::resize(&img, height, width, ::image::imageops::FilterType::Triangle);
2727
let mut flat_img: Vec<f32> = Vec::new();
2828
for rgb in resized.pixels() {
29-
flat_img.push(rgb[0] as f32 / 255.);
30-
flat_img.push(rgb[1] as f32 / 255.);
31-
flat_img.push(rgb[2] as f32 / 255.);
29+
flat_img.push(rgb[0] as f32 / 255.0);
30+
flat_img.push(rgb[1] as f32 / 255.0);
31+
flat_img.push(rgb[2] as f32 / 255.0);
3232
}
3333
let bytes_required = flat_img.len() * 4;
3434
let mut u8_f32_arr: Vec<u8> = vec![0; bytes_required];
@@ -40,7 +40,7 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
4040
let u8_bytes = u8_f32.to_ne_bytes();
4141

4242
for j in 0..4 {
43-
u8_f32_arr[((flat_img.len() / 3 * c + i) * 4) + j] = u8_bytes[j];
43+
u8_f32_arr[((i * 3 + c) * 4) + j] = u8_bytes[j];
4444
}
4545
}
4646
}

tf-mobilenet-image/rust/tf-mobilenet/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn image_to_tensor(path: String, height: u32, width: u32) -> Vec<u8> {
117117
let u8_bytes = u8_f32.to_ne_bytes();
118118

119119
for j in 0..4 {
120-
u8_f32_arr[((flat_img.len() / 3 * c + i) * 4) + j] = u8_bytes[j];
120+
u8_f32_arr[((i * 3 + c) * 4) + j] = u8_bytes[j];
121121
}
122122
}
123123
}
Binary file not shown.

0 commit comments

Comments
 (0)