openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.18k stars 2.24k forks source link

[Bug] Mismatch in layout between model and code in hello_reshape_ssd.py #11329

Closed dtoya closed 2 years ago

dtoya commented 2 years ago
System information (version)
Detailed description

I observed an error when I run hello_reshape_ssd.py in openvino sample by following the steps in OpenVINO developer document. https://docs.openvino.ai/latest/openvino_inference_engine_ie_bridges_python_sample_hello_reshape_ssd_README.html#

It looks the error is caused by mismatch in layout between the code and actual model (ssdlite_mobilenet_v2) used in the document. The sample could run by changing layout from NCHW to NHWC for model.

    n, h, w, c = input_tensor.shape
    model.reshape({model.input().get_any_name(): PartialShape((n, h, w, c))})

    # 2) Here we suppose model has 'NCHW' layout for input
    ppp.input().model().set_layout(Layout('NHWC'))
Steps to reproduce
$ omz_downloader --name ssdlite_mobilenet_v2
$ omz_converter --name ssdlite_mobilenet_v2
$ wget https://storage.openvinotoolkit.org/data/test_data/images/banana.jpg
$ python3 hello_reshape_ssd.py public/ssdlite_mobilenet_v2/FP32/ssdlite_mobilenet_v2.xml banana.jpg CPU
[ INFO ] Creating OpenVINO Runtime Core
[ INFO ] Reading the model: /data/intel/open_model_zoo/models/public/ssdlite_mobilenet_v2/FP32/ssdlite_mobilenet_v2.xml
[ INFO ] Reshaping the model to the height and width of the input image
Traceback (most recent call last):
  File "hello_reshape_ssd.py", line 120, in <module>
    sys.exit(main())
  File "hello_reshape_ssd.py", line 53, in main
    model.reshape({model.input().get_any_name(): PartialShape((n, c, h, w))})
RuntimeError: Check 'input_shape[1].compatible(filters_shape[1])' failed at core/shape_inference/include/convolution_shape_inference.hpp:265:
While validating node 'v1::Convolution FeatureExtractor/MobilenetV2/Conv/BatchNorm/batchnorm/mul_1 (Preprocessor/sub[0]:f32{1,300,3,300}, FeatureExtractor/MobilenetV2/Conv/weights/read/_101__cf__104[0]:f32{32,3,3,3}) -> (f32{1,32,150,150})' with friendly_name 'FeatureExtractor/MobilenetV2/Conv/BatchNorm/batchnorm/mul_1':
Data batch channel count (300) does not match filter input channel count (3).
Issue submission checklist
vladimir-dudnik commented 2 years ago

@mgrdv could you please take a look at this issue?

mgrdv commented 2 years ago

@dtoya , hello_reshape_ssd sample is designed to support models with NCHW layout, this is not a universal tool. If you need a universal app then please use the OMZ demo.

ilya-lavrenov commented 2 years ago

@dtoya , hello_reshape_ssd sample is designed to support models with NCHW layout, this is not a universal tool. If you need a universal app then please use the OMZ demo.

is it states on sample documentation?

dtoya commented 2 years ago

Hi @ilya-lavrenov, yes, the model is used in the sample documentation. If the code will not be changed, the model should be changed to avoid confusing users. (C++ version is using different model.)

jgespino commented 2 years ago

@dtoya Thanks for your feedback, I have opened an internal ticket to update the documentation.

Ref. 84516