-
Notifications
You must be signed in to change notification settings - Fork 862
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
Limitation in processing number of video frames according to GPU memory? #36
Comments
There are multiple things you could do.
I would go with number 3, with pseudo code being something like. this isn't tested, it's just to give you an idea
Like I said, I haven't tested it, but it could be a bit of work to get it implemented from scratch as I haven't looked into how the models are loaded into memory yet. The above is definitely enough to work out your own solution though without messing with torch though. |
Ok. |
Great to hear. I would try to create a little wrapper function where you can tune your own parameters (max frame count), and plug it into line 50 where it executes |
Yes. |
So I need little bit of help.
Then it begins to write the video_file(1) containing the first 98 frames Is there a way to jump back to video_swap but continue with frame 99 for the next 98 frames? EDIT. |
The way torch.cuda.empty_cache() works is it only frees the memory that it's able to. Remember what I said about me not being aware of how the models are loaded into memory with this project? This is what I was referring to. They may be instantiated in different parts of the script, so it may be a bit more work, but you can try what I said below. Also, you're running that torch call every frame which isn't necessary / can lead to some issues. Also, you don't need to use user input to go to the next iteration. It probably runs out of memory because it's still executing in the background while waiting for your input. Try this instead (untested as I'm away from my machine).
|
The user input is just for some testing purpose after 98 frames. |
Read my proposed code again please. It's not about setting the frame index to 0, it's about creating a separate counter variable that increases a certain amount of times in the loop, and once it hits a certain limit (max_frame), the counter resets. You said that your GPU runs out of memory every 15th frame or so. In theory, clearing your GPU cache via torch's methods (which may not work) or doing something to alleviate GPU resources every 15 frames would prevent you from doing all of the extra steps you've mentioned. |
Looks like i accidently got it to work on 2GB GPU VRAM.... Not the way I initially planned .... but it works. As soon as I have cleaned up the code I will post the changes I've made. EDIT: |
Here are the changes I made to run SimSwap on 2GB VRAM: ./options/test_options.py self.parser.add_argument("--first_frame", dest="first_frame", type=int, default=0, help="Set frame to start from.") ./util/videoswap.py test_video_swapsingle.py first_frame = 2 test_video_swapsingle.py calls video_swap in ./util/videoswap.py and processes the first 2 frames before the break Not perfect but (working for me)..... |
Just found a more simple solution for "cuda out of memory" problem while running SimSwap on 2GB GPU: I only insert a with torch.no_grad(): command in ../util/videoswap.py between lines 48 and 49 and it works perfect |
OMG, I forgot to add this .I will make it done in the next update. |
:-) |
Since I got it to work on my GForce 1050GTX / 2GB , at least for videos not longer than ~ 16 frames, before the GPU runs out of memory I wonder if there is also a limitation for using a 8 GB GPU ?
I had the same problem using Wav2Lip, but it could be solved by setting the chunk size to 1.
Would it (theoretically) be possible to process videos in SimSwap in smaller parts or chunks by releasing GPU memory every 15 frames ?
The text was updated successfully, but these errors were encountered: