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
Make .detect_video
more memory efficient
#139
Comments
detect_video
.detect_video
more memory efficient
Hi, first of all, really great work! I was very happy to see the v0.5 release. I ran into this issue when using your The advantage of this solution is that it does not depend on pytorch's I hope this may be helpful. |
Thanks @maltelueken this super helpful! We're currently trying an approach in #170 to "lazy" load video-frames using pyav. Would love your thoughts/any testing you might be able todo with this approach! |
@ejolly @ljchang Hi, I would like to understand why it seems that the time that it takes to process each iteration increases ~lineally with video length. With batch_size=1, it starts at 1.00s/it. By frame 150, it has already doubled and by frame 300, it reaches 3.10s/it. I think this makes running detect_video on large files implausible. Prediction wise, should it make a difference if I split the video into 60s or 10s chunks? Thanks in advance for any recommendations. Kind regards. My system: i7-7700, 50gb ram, rtx 3060 12vram, ubuntu 22.04, feat version '0.6.1' My detector: .detect_video(video_path=mp4_file, My file (ffmpeg -i -f) : |
Hey @juaninachon this was a conscious design decision on our part until Pytorch natively handles videos in a more efficient way without additional installation overhead. By default Pytorch tries to read every frame from a video file into RAM at once before passing batches to the GPU. A lot of our users complained that There should be no difference between cutting the video into segments and processing them independently if that helps speed things up! |
Thank you for your thoughtful reply on these innerworkings.
Sincerely,
Juan
…On Tue, Jan 2, 2024, 17:46 Eshin Jolly ***@***.***> wrote:
Hey @juaninachon <https://github.com/juaninachon> this was a conscious
design decision on our part until Pytorch natively handles videos in a more
efficient way without additional installation overhead. By default Pytorch
tries to read every frame from a video file into RAM at once before passing
batches to the GPU. A lot of our users complained that pyfeat would crash
silently because they were running out of memory when processing videos.
Our current solution "seeks" to each frame in the video and discards
previous frames before passing batches to the GPU. What you're noticing is
the linearly increasing "seek" time, which we decided was a better
trade-off than running out of memory, until we or torch has a more
efficient native solution.
There should be no difference between cutting the video into segments and
processing them independently if that helps speed things up!
—
Reply to this email directly, view it on GitHub
<#139 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMGB3HFPMKIK4KMFC5S6G63YMRW2NAVCNFSM6AAAAAAQXHIUGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZUGUZDQNBYHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@ljchang after chatting with @TiankangXie it looks like we can fairly easily roll our own
read_video
function becausetorch
also provides a lower level API with theirVideoReader
class.Just like in their examples, we can just write a function that wraps the
next(reader)
calls and return a generator so at most we load onlybatch_size
frames at most into memory on each loop iteration. That way even long videos shouldn't be a problem on low RAM/VRAM machines, and more memory will simply allow for bigger batch sizes.The downside trying to get it to work right now is that
torch
needs to be compiled with support for it and requires a workingffmeg
install:So it seems like the real cost of rolling our own solution with
VideoReader
untiltorch
allows for more memory efficientread_video()
, is an added dependency onffmepg
and potentially more installation hassle. Or we can try a different library or solution for loading video frames. From a brief search on github it looks like there are lots of custom solutions as third party libraries, because this isn't quite "solved." But most libraries "cheat" a bit IMO. e.g. Expecting that you've pre-saved each frame as a separate image file on diskThe text was updated successfully, but these errors were encountered: