Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

Hello Classification C++ modification

Omkar2
Beginner
2,377 Views

Hi,

I was following this Hello Classification C++ example  and rather than reading a raw image, wanted to read an already saved tensor file eg. this file  (this is from an example about using wasi-nn and uses this tool to convert image into a tensor file) and perform the inference.

I tried changing the lines 515-60 in this code to the following (basically reading raw bytes of the file and create the Tensor object):

Omkar2_0-1663553767685.png

 

But on running this it just gives a Segmentation Fault at this step

Omkar2_2-1663554258279.png

 

Weirdly, I tried to do a similar thing in Python (as shown below) and it works perfectly. 

Omkar2_1-1663553855925.png

Any suggestions on how I can go about making it work?

0 Kudos
10 Replies
Wan_Intel
Moderator
2,336 Views

Hi Omkar2,

Thanks for reaching out to us.

 

I’ve validated Hello Classification Python Sample by loading image file (tensor format) as input data.

 

Wan_Intel_0-1663651184716.png

 

 

Could you please share your C++ inference script with us for replication purposes?

 

 

Regards,

Wan

 

0 Kudos
Omkar2
Beginner
2,304 Views

Hi Wan

 

Have attached the C++ file, most things are the same as the Hello Classification example but some arguments have been added . Once compiled the usage should be as follows: 

`./hello_classification <model_root_path> <model_name> <tensor_file_path> <tensor_height> <tensor_width> <precision> <device>`

eg. `./hello_classification public/mobilenet-v2/FP32 mobilenet-v2 tensor-1x224x224x3-f32.bgr 224 224 f32 CPU`

 

Please do let me know if any other information will help!

 

Thanks,

Omkar

0 Kudos
Wan_Intel
Moderator
2,271 Views

Hi Omkar2,

Thanks for sharing your information with us.

 

We encountered the same issue when running your custom Hello Classification C++ sample. We’re investigating this issue and we’ll get back to you at the earliest.

 

 

Regards,

Wan


0 Kudos
Wan_Intel
Moderator
2,206 Views

Hi Omkar2,

Thank you for your patience, we do suggest to change infer_request.set_input_tensor(input_tensor) in Step 7 to infer_request.get_input_tensor() while importing the tensor file.

 

ov::InferRequest allows you to get input/output tensors by tensor name, index, port, and without any arguments, if a model has only one input or output.

 

Additional information can be obtained in OpenVINO™ Inference Request. Thank you.

8.png 

 

 

Regards,

Wan

 

0 Kudos
Omkar2
Beginner
2,177 Views

Hi Wan,

 

Thanks for getting back. I didn't quite understand how get_input_tensor() helps when we need to give our input tensor. 

 

If you could share the code (main.cpp) that you used to make this work with the tensor file, it would be really helpful.

 

Thanks,

Omkar 

0 Kudos
Wan_Intel
Moderator
2,158 Views

Hi Omkar,

You may refer to the main.cpp file that we've attached to this post. Hope it helps.

 

 

Regards,

Wan

 

0 Kudos
Omkar2
Beginner
2,120 Views

Hi Wan,

 

The get_input_tensor() definitely doesn't work (as it a getter method). The model just uses some default tensor value and produces the output, if you use another tensor file it will produce the same results (see the screenshots below as tested).

 

Please do let me know if there is any solution to fix the set_input_tensor method.

 

Thanks,

Omkar

0 Kudos
Wan_Intel
Moderator
2,110 Views

Hi Omkar2,

Thanks for your information.

 

We encountered the same issue as you when using the get_input_tensor() with another image as an input. We're investigating this issue and we'll update you at the earliest.

 

gg.png

 

 

Regards,

Wan

 

0 Kudos
Wan_Intel
Moderator
2,066 Views

Hi Okmar2,

Thanks for your patience.

 

Segmentation fault is a specific kind of error caused by accessing memory, there is a discussion on segmentation fault can be found in https://stackoverflow.com/questions/2346806/what-is-a-segmentation-fault/2346849#2346849

 

It is suggested to remove "&" in ov::Tensor input_tensor = ov::Tensor(input_type, input_shape, data);.

 

The "&" may be one of the reasons caused the segmentation fault error previously.

 

Thank you.

 

good.png

 

Regards,

Wan

 

0 Kudos
Wan_Intel
Moderator
1,994 Views

Hi Omkar2,

Thanks for your question.

This thread will no longer be monitored since we have provided information. 

If you need any additional information from Intel, please submit a new question.

 

 

Best regards,

Wan


0 Kudos
Reply