Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? Input tensor size mismatch for RGB image inference #150

Closed
Dong148 opened this issue Oct 14, 2024 · 4 comments
Closed

Bug? Input tensor size mismatch for RGB image inference #150

Dong148 opened this issue Oct 14, 2024 · 4 comments

Comments

@Dong148
Copy link

Dong148 commented Oct 14, 2024

Summary:
I am encountering an issue where the input tensor size does not match the size of the RGB image data when attempting to perform inference using the openvino-rs library.

Code:
`
fn run_image_rbg(&mut self, image: &RgbImage) -> Result<Vec, OpenVINOInferSessionError> {
let (width ,height) = image.dimensions().into();
let (width,height) =(width as i64,height as i64);

    let image_shape = Shape::new(&[height , width, 3]).map_err(
        |e| { OpenVINOInferSessionError::OpenVINOInferenceError(e) }
    )?;

    let mut input_tensor = Tensor::new(ElementType::U8, &image_shape).map_err(
        |e| { OpenVINOInferSessionError::OpenVINOInferenceError(e) }
    )?;
    let image_data = image.as_raw();
    input_tensor.get_raw_data_mut().map_err(
        |e| { OpenVINOInferSessionError::OpenVINOInferenceError(e) }
    )?.copy_from_slice(image_data);

`
Runtime error:
source slice length (847356) does not match destination slice length (317760)

Steps to Reproduce:

Load an PNG with dimensions 482x586 as RGBImage .
Create a Tensor with ElementType::U8 and Shape(586,482,3)
Prepare the image data, which results in a buffer of size 847356 (482 * 586 * 3).
Attempt to create an input tensor and copy the image data into it using the run_image_rbg function.

Expected Behavior:

The input tensor should be allocated with the correct size to accommodate the image data, and the data should be copied successfully without any errors.

Environment:
OS: CentOS Stream 9
openvino-rs: 0.7.3
rust: rustc 1.77.2 (25ef9e3d8 2024-04-09) (Red Hat 1.77.2-3.el9)

I have verified that the image dimensions and data size are correct. It appears that there might be an issue with tensor allocation within the library. Please assist in resolving this issue or provide guidance on any additional steps required to correctly prepare the input tensor.

I am a Rust beginner and there might be some misunderstandings or mistakes on my part while using the library. Could it be possible that there is an issue in my code that is causing this mismatch error? Your assistance and guidance would be greatly appreciated.

@Dong148
Copy link
Author

Dong148 commented Oct 14, 2024

I run the official example:
let data = [1u8; 1000]; let shape = Shape::new(&[10, 10, 10])?; let mut tensor = Tensor::new(ElementType::U8, &shape)?; tensor.get_raw_data_mut()?.copy_from_slice(&data);
got:
source slice length (1000) does not match destination slice length (375)

@Dong148
Copy link
Author

Dong148 commented Oct 14, 2024

I run the official example: let data = [1u8; 1000]; let shape = Shape::new(&[10, 10, 10])?; let mut tensor = Tensor::new(ElementType::U8, &shape)?; tensor.get_raw_data_mut()?.copy_from_slice(&data); got: source slice length (1000) does not match destination slice length (375)

link to doc

@Dong148
Copy link
Author

Dong148 commented Oct 14, 2024

I Fixed it.
prev:
Env:
openvino: 2024.4.0...

now:
openvino: 2024.1.0.15008-1

Reference

@Dong148 Dong148 closed this as completed Oct 14, 2024
@abrown
Copy link
Contributor

abrown commented Oct 14, 2024

@Dong148, looks like you were running into the same essential problem as #143: using an older version of the bindings with a new version of the upstream library will surface some breaking changes that OpenVINO introduced. The plan is to add a version check in #149 that, once released, should prevent this confusion in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants