hotg-ai / rune

Rune provides containers to encapsulate and deploy edgeML pipelines and applications
Apache License 2.0
136 stars 15 forks source link

Showing wrong data type #286

Closed Mohit0928 closed 3 years ago

Mohit0928 commented 3 years ago

While running Rune model-info model.tflite for Pose Estimation model, it gives

Inputs:
        sub_2: Float32[1, 353, 257, 3]
Outputs:
        float_heatmaps: Float32[1, 23, 17, 17]
        float_short_offsets: Float32[1, 23, 17, 34]
        float_mid_offsets: Float32[1, 23, 17, 64]
        float_segments: Float32[1, 23, 17, 1]

When I put image outputs type as "f32" as shown below:

pipeline:
  image:
    capability: IMAGE
    outputs:
      - type: f32
        dimensions: [1,353,257,3]
    args:
      pixel-format: "@PixelFormat::RGB"
      height: 353
      width: 257

When I tried to build the Rune, it throws an error:

error[E0308]: mismatched types
  --> lib.rs:51:40
   |
51 |         let image_out_0: Tensor<f32> = image.generate();
   |                          -----------   ^^^^^^^^^^^^^^^^ expected `f32`, found `u8`
   |                          |
   |                          expected due to this
   |
   = note: expected struct `hotg_rune_core::Tensor<f32>`
              found struct `hotg_rune_core::Tensor<u8>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `pose_detection` due to previous error
Error: Rune compilation failed

Caused by:
    0: Compilation failed
    1: Cargo exited with a return code of 101

Why it's showing "u8" datatype even when I am passing "f32"?

Michael-F-Bryan commented 3 years ago

It shows u8 because image capabilities generate RGB images where each pixel is an 8-bit integer.

Can you explain what you expected to happen here or what you thought Rune should be doing under the hood when you say the output type is a f32 tensor with dimensions [1,353,257,3]?

Mohit0928 commented 3 years ago

Ohh, got it. Earlier I thought it could also accept output type as f32. It gets resolved by first setting image capabilities to generate RGB images where each pixel is an 8-bit integer and later using "image_normalization" proc-block to convert into "f32".

pipeline:
  image:
    capability: IMAGE
    outputs:
      - type: u8
        dimensions: [1,353,257,3]
    args:
      pixel-format: "@PixelFormat::RGB"
      height: 353
      width: 257
  image_normalization:
    proc-block: "hotg-ai/rune#proc-blocks/image-normalization"
    inputs:
      - image
    outputs:
      - type: f32
        dimensions: [1,353,257,3]

Thanks

Mohit0928 commented 3 years ago

Closing the issue