AlexeyAB / darknet

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

Darknet Video Python Script Thread Keeps Running #8037

Open aditya-AI opened 3 years ago

aditya-AI commented 3 years ago

Hi @AlexeyAB kindly help.

When I run the darknet_video.py as python darknet_video.py --input /darknet/Sample.mp4 --weights yolov1.weights --config_file cfg/yolov1/yolo.cfg --data_file ./cfg/voc.data --dont_show --out_filename res.mp4 the script keeps running.

Please find attached the screenshots: darknet-video-bug

The below screenshot shows the output when I hit ctrl+c:

darknet-video-bug-interrupt

What I understood from this error is that since we have 3 threads running, as soon as the VideoCapture reads all the frames it calls cap.release() because of which the drawing function exits from the while loop. The code is stuck in the inference function at detections_queue.put(detections) it is not able to put more detections since queue size is 1 and the drawing function was not able to execute detections = detections_queue.get(). Hence, the detections_queue is not empty and apparently, the inference function keeps waiting for this queue to get empty.

I have added few flags to take care of this issue such that the drawing function exits while loop only when the inference function is finished.

There needs to be some mechanism to create a sync between all three threads.

johnny12150 commented 3 years ago

What I understood from this error is that since we have 3 threads running, as soon as the VideoCapture reads all the frames it calls cap.release() because of which the drawing function exits from the while loop. The code is stuck in the inference function at detections_queue.put(detections) it is not able to put more detections since queue size is 1 and the drawing function was not able to execute detections = detections_queue.get(). Hence, the detections_queue is not empty and apparently, the inference function keeps waiting for this queue to get empty.

I have noticed this would cause some frames lost in the final output video.

I have added few flags to take care of this issue such that the drawing function exits while loop only when the inference function is finished.

How did you solve the issue? Could you provide the code that has been fixed?