Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darknet_video.py off by 1 frame #6706

Open
mazatov opened this issue Sep 21, 2020 · 9 comments
Open

darknet_video.py off by 1 frame #6706

mazatov opened this issue Sep 21, 2020 · 9 comments

Comments

@mazatov
Copy link

mazatov commented Sep 21, 2020

Running darknet_video.py on the video makes a video where the detections and the video are off by one frame.

The amount of frames it's off by seems to depend on max_size of the darknet_image_queue

@mazatov
Copy link
Author

mazatov commented Sep 21, 2020

Also, not clear why max_size =1 for the queues. Larger max_size would speed things up. Seems like the author suspected that to be a problem.

@mazatov
Copy link
Author

mazatov commented Sep 22, 2020

Update. The darknet_image is overwritten in video_capture every time it's being created because it sits in the same memory so effectively the darknet_image_queue is not working properly

Proposed fix here:

First time doing PR here @AlexeyAB , so let me know if I need to do more. Seems like darknet detector demo has the same error though so possibly it's in C++ code too but I don't know enough to make changes there.

@Tacokeet
Copy link

Hey @mazatov, I also found this problem, thanks for the solution. The delay within the darknet detector demo can be fixed by adding the flag -avgframes 1 found here #5806.

@mazatov
Copy link
Author

mazatov commented Sep 22, 2020

Thanks didn't know about this flag -avgframes 1 option.

Still, it's a bit of hackish fix as it assumes that cv2.videoreader is going to work faster than darknet.detect_image and the frame in the queue will always be overwritten by the next frame. While it's true for most computer hardware, I can imagine a situation where detect_image outperformed cv2.videoreader and you would suddenly not have that 1 shift in frames.

My proposed fix gets rid of the problem without any sacrifice in speed(at least on my computer)

@Tacokeet
Copy link

Okay I just tried it out on my computer.
It fixes the 1 frame problem but there is memory problem. It keeps ramping up the memory usage until it crashes.

@mazatov
Copy link
Author

mazatov commented Sep 22, 2020

Good point, if you have a long video and GPU can't keep up with the loading it would happen. I should add maxsize to the queues so they don't load too much into memory. I put maxsize to 250 for all queues to avoid this problem.

@mazatov
Copy link
Author

mazatov commented Sep 28, 2020

@Tacokeet , I was still getting a memory problem so I worked on it a bit more. I did a hacky fix to the issue, but it works. You can check the updated PR.

@Tacokeet
Copy link

Thanks for the update! Seems you forgot to push the correct version because 'darknet_images' is not defined. But after adding it seems to run nice. I can now finish a ~9 min video without any memory issues.

@mazatov
Copy link
Author

mazatov commented Sep 29, 2020

Oh, right! Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants