LdDl / rust-road-traffic

Vehicle counting/tracking and speed estimation
19 stars 3 forks source link

YoloV8, Hough lines, ONNX support? #17

Closed dancixx closed 8 months ago

dancixx commented 11 months ago

Hey there,

First off, hats off for creating such a fantastic product! 🚀

Just a couple of thoughts:

Any chance we could see support for newer Yolo versions or importing onnx files? How about integrating Hough lines detection to save us from manually drawing those boxes?

LdDl commented 11 months ago

Hello! Thanks for very kind words)

Yeah, I'm planning to move to full ONNX support since even v3/v4 version of YOLO could be converted into it and ONNX is considered to be standart-ish in industry.

What about YOLOv5/YOLOv7/YOLOv8 and other Ultralytics stuff? Currently I'm learning YOLOv8 Nano variation and prototyping in Python inference for it via OpenCV (since I do no want to introduce Pytorch here) and have a bit struggling to represent class scores, but it is on my way. Of course, the training part is done in Pytorch and I'll create another repo similar to yolo_vehicles

And the last part: Hough lines I assume that user should markup detection region by his own hands, since there could not be roadmarkup on the road at all. Hough lines could be helpful, but only if it is done not by detection software, but with UI side of it

dancixx commented 11 months ago

If I am honest, I try to avoid Python, that is the reason why I'm asking for ONNX support. Over the weekend I modified the package to use the ONNX via the OpenCV dnn module, but the algorithm you are using for some reason couldn't handle the results from the forward method. I don't understand why, but I will investigate further and can help integrate ONNX support. :)

I will check your Python library too. For the Hough line cases, I tried to draw them using OpenCV edge detection, but there are too many similar line-like road lines. One more idea I have is to use Yolo for this problem too.

dancixx commented 11 months ago

Yesterday I tried to refactor the project using onnx opencv::dnn:read_net_from_onnx, it seemed everything worked fine but the inference did not happen. I am not sure if that is possible right now because maybe the Yolo model contains such layers which are not supported currently in opencv dnn module, so maybe should use some other different NN framework like rust tensorflow binding or tch-rs. I checked Candle, but there is an open issue that the inference is much slower than onnxruntime or pytorch in Python.

LdDl commented 10 months ago

I'm back here again.

So, I've tested ONNX for v8 (from small variation up to extra large) and it works good, but inference functions is different from traditional YOLO-family. https://github.com/LdDl/object-detection-opencv-rust/blob/master/src/model_ultralytics.rs#L155

Also, I've noticed that OpenCV 4.6.0 is not working with YOLOv8 (onnx + opset=12). Therefore I've switched to OpenCV 4.7.0

I think I should import different inference models in this repository too and in further implement inference for YOLO v5 also.

dancixx commented 10 months ago

Thanks for the update. I will check it, maybe to join as a contributor for the package. :)

LdDl commented 10 months ago

Another update (2023.12.04): Just bumped main branch with integration of model trait (see the ref #18), so we are free to use either traditional YOLO or Ultralytics one. But, be aware: OpenCV <= 4.6.0 is not working with YOLOv8.

LdDl commented 8 months ago

I think we can consider this issue to be closed. Results: