AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.65k stars 7.96k forks source link

Improve detection speed for darknet_video.py #3056

Open AlexeyAB opened 5 years ago

AlexeyAB commented 5 years ago

Improve detection speed on video for python script darknet_video.py

Use multiple CPU-threads, at least 3 threads:

  1. create duplicate image, resize it to network size, convert to image FP32-type
  2. run yolo-detection
  3. draw bounded boxes on original image and show this image (this or 4th-thread - save output to video mp4-file)
migvel commented 5 years ago

Hi Alexey, thanks for your work.

I'm not sure if this proposal will increasse the speed, at least substantially.

I checked the FPS from the contribution only of the function: detections = darknet.detect_image(netMain, metaMain, darknet_image, thresh=0.25)

And with my card, GeforceGTX 1070TI I get from around FPS=9.7 the full code, to FPS=9.1 aprox. for only the detection.

So my guess is that the bottle neck of speed in Python should be inside detect_image, or do I'm wrong? Where do you think is the slowdown form C++ to Python? In C++ it goes like a 3x faster.

Please let me know your opinion I would be interested to contribute. Regards!

LukeAI commented 5 years ago

in c++ you get ~27fps and only 9fps with the python?

migvel commented 5 years ago

Yes(even higher in c++), I see the ussage of the GPU-util. differs:

LukeAI commented 5 years ago

That's shocking! I haven't actually directly compared, myself but I'm getting roughly the results I expect with python. What weights/config are you using? how do you test? I'll try and reproduce your results, I have a python wrapper based on darknet_video.py - maybe I can help work out why it's so bad in your case.

migvel commented 5 years ago

Thanks LukeAI,

I test it with the default version of darknet_video.py loading a mp4 file. In c++ I use ./darknet.exe detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -ext_output test.mp4 all config is default.

Both are using yolov3.cfg

migvel commented 5 years ago

After looking and playing around the yolo_cpp_dll and its dependencies, I think after I rebuilt it, started to run faster in Python. Now runs around 1/3 faster in c++ than in Python, that's reasonable.

Regards.

IbrahimBond commented 5 years ago

@migvel what exactly did you do exactly? because using the python3 script i am getting around 40 fps where using the c++ (detector demo) i am getting 80-90 fps

@AlexeyAB can you explain what is heppening here? does the C++ code use threading or more optimized in anyway?

faybak commented 5 years ago

hello @IbrahimBond did you find an answer about this difference between c++ and python regarding fps please ? Thanks