openvinotoolkit / open_model_zoo

Pre-trained Deep Learning models and demos (high quality and extremely fast)
https://docs.openvino.ai/latest/model_zoo.html
Apache License 2.0
4.1k stars 1.37k forks source link

Using the 2.0 API gives bad results with YOLO models #3470

Closed AntalZsiros closed 1 year ago

AntalZsiros commented 2 years ago

We have compiled the object detection demo for the new 2022.1 openvino: https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/object_detection_demo/

When running the demo, we load one of our own models, which gave correct results with the previous version of this demo (openvino version 2021.4).

The object detection demo for openvino 2021.4 returns this result: 2021 4

However the object detection demo for openvino 2022.1 returns this result: 2022 1

In both cases we use exactly the same model and run the demo with the same parameters. The only difference is that the object detection demo for 2021.4 was using api 1.0, while the object detection demo for 2022.1 is now using api 2.0.

Possible reason: I have seen a similar bug before, when openvino support was added to the opencv project. There, the cause of the problem was that someone had written into the opencv code that the input size of the yolo model could only be 416x416 which was a false assumption. The input size of the model I am using is 128x128. (I saw that the parseYOLOOutput function had to be given an input size and I changed it to use a size of 128, but it had no effect.)

eugene123tw commented 2 years ago

Hi @AntalZsiros, could you share the command line you used to run the model and the dataset? I can take a look

This is the result I got running on one of the test images in https://github.com/detectRecog/CCPD

Screenshot from 2022-05-18 15-21-34

python object_detection_demo.py -d CPU -i CCPD2020/ccpd_green/test -m public/vehicle-license-plate-detection-barrier-0123/FP32/vehicle-license-plate-detection-barrier-0123.xml -at ssd
AntalZsiros commented 2 years ago

Hi @eugene123tw This error was caused by a private model and not a public one.

I start the demo with the following flags : -i "D:/test.mp4" -at "yolo" -m "C:\work\frozen_darknet_yolov4_model.xml" -t 0.5 -nireq 1 -nstreams 4 -nthreads 4 -d CPU

This model produces correct results with OpenVino 2021.4 and the corresponding object detection demo which was using V1 api. However, when we are using openvin 2022.1 where the object detection demo demonstrates the use of V2 api the outputs are incorrects.

The object detection demo for openvino 2022.1 release was created to show V2 API: https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/object_detection_demo/

Probably when this demo was rewritten to use V2 API, a bug was added to the parsing methode: https://github.com/openvinotoolkit/open_model_zoo/blob/master/demos/common/cpp/models/src/detection_model_yolo.cpp#L302

Our company code uses the V1 api and it's my job to rewrite the code to use the new V2 api with this yolo model. Otherwise, if we use openvino 2022.1 in our code via V1 api we still get correct results. Based on the documentation, I wrote the code to run the model via V2 API, but I got incorrect results as output.
So I checked what result I get with the new object detection demo which now uses V2 api, but I got the same wrong result as with the code I wrote.

I've seen this before when openvino and opencv first time included the ability to run yolov4 models. It was written into the code that the input size could only be 416x416, which is incorrect. I put an issu ticket on it and it was fixed, but now it came back. The model I'm looking at now has an input size of 128x128.

It is possible that the bug is deeper and not in the code of the demo, but in the openvino itself.

Is this ticket in the right place or should I open a new one elsewhere ?

Wovchena commented 2 years ago

@AntalZsiros, there is a fix for yolov4 https://github.com/openvinotoolkit/open_model_zoo/pull/3463. Try if it works for you. If not, I will need a way to reproduce the problem with one of Open Model Zoo models.

tsantra commented 2 years ago

@AntalZsiros did it fix your issue?