learnopencv icon indicating copy to clipboard operation
learnopencv copied to clipboard

object detection using Yolo v5 c++ working?

Open chyphen777 opened this issue 2 years ago • 4 comments

Is the C++ version of Object Detection using Yolov5 working? I ran it with sample.jpg and yolov5s.onnx, but it output zero index. (at line 122/123 of yolov5.cpp. Any help will be appreciated.

chyphen777 avatar Apr 25 '22 02:04 chyphen777

Are you talking about the sample Object-Detection-using-YOLOv5-and-OpenCV-DNN-in-CPP-and-Python/yolov5.cpp?

It did not even compile for me, needed to adapt line 168 to make a separate copy/clone, as the method post_process()expects a non-const-reference.

After this I get a runtime-exception in pre_process() while net.forward(outputs, net.getUnconnectedOutLayersNames());:

terminate called after throwing an instance of 'ngraph::NodeValidationFailure'
  what():  Check 'PartialShape::broadcast_merge_into( pshape, node->get_input_partial_shape(i), autob)' failed at core/src/op/util/elementwise_args.cpp:40:
While validating node 'v1::Multiply Multiply_546 (470[0]:f32{1,3,80,80,2}, Constant_545[0]:f32{1,38400,1,1,1}) -> (dynamic?)' with friendly_name 'Multiply_546':
Argument shapes are inconsistent.

Can you describe your code-changes, please?

brmarkus avatar Apr 25 '22 05:04 brmarkus

are you using the latest version of OpenCV? I think the code works if the version is > 4.5.4

vikasgupta-github avatar Apr 25 '22 06:04 vikasgupta-github

Sorry! I was using OpenCV in version 4.5.3 (from an OpenVINO v2021.4.2). Using a Python virtual-env, now I'm using v4.5.5 and see the Python version "yolov5.py" working.

I cloned opencv and opencv_contrib from the branch "4.5.5", built it. And can confirm the C++ variant "yolov5.cpp" is working now as well: image

But I needed to adapt line 168 to make a separate copy/clone, as the method post_process() expects a non-const-reference.

brmarkus avatar Apr 25 '22 07:04 brmarkus

I also had to change the line 167 ,,frame.clone()'' to just frame. It worked and i also have Opencv 4.5.4 So this version also runs fine.

ghost avatar Apr 27 '22 09:04 ghost