Closed MaxTeselkin closed 1 year ago
I don't see anything wrong with your code at a glance except appending the final predictions to a list (but it should use CPU memory). Memory leaking is likely happening somewhere and it is probably not in InferenceCore
(you can test with eval.py
for this). Can you narrow down the potential lines where memory leaking happens (e.g., with https://stackoverflow.com/questions/58216000/get-total-amount-of-free-gpu-memory-and-available-using-pytorch)?
Hi @hkchengrex, thanks for answer. I followed your advice and checked GPU memory usage on every iteration, and it is constantly growing with every frame.
I tried adding the following lines of code to my predict function to free GPU memory from frames that were already passed to model, but it gave no results:
# remove frame and mask from GPU
input_mask.cpu()
frame.cpu()
It is written in your paper that XMem has low memory usage. Maybe you have some memory optimization algorithms like LRU and I am not using them?
If you are using InferenceCore
with the config that you gave, you are already using the memory management algorithm. This is why I wonder if there are other lines of code that can potentially cause a memory leak.
@hkchengrex No, honestly I send you all code which is used for running XMem. Right now I am resizing smaller size to 480 and larger size proportionally. I can try resizing to lower resolution, let's say 320, but it still does not answer the question why my XMem integration code turned out to be so memory consuming
I also tried decreasing "min_mid_term_frames" and "max_mid_term_frames" to save memory as proposed in your eval.py script, but it didn't give me significant results
@hkchengrex No, honestly I send you all code which is used for running XMem. Right now I am resizing smaller size to 480 and larger size proportionally. I can try resizing to lower resolution, let's say 320, but it still does not answers the question why my XMem integration code turned out to be so memory consuming
I mean this is not "runnable". WIth 24G you should be able to run 480p videos comfortably.
I also tried decreasing "min_mid_term_frames" and "max_mid_term_frames" to save memory as proposed in your eval.py script, but it didn't give me significant results
Should not be relevant.
One more thing -- how many objects are there?
I have only 1 object. I added some lines of code to your tutorial colab to check GPU memory usage on every iteration and it is a lot lower than mine. But the code is almost the same. I am totally confused.
Here is how my free GPU memory decreases with every single frame:
While running your code in Colab shows significantly lower memory consumption:
So every single frame takes almost 500 MB GPU memory for me, I have no idea why is it happening
Then I'm afraid that it is from other parts of the code or the environment. Unfortunately, I cannot help with either of those.
Actually, can it be that autograd is on? In eval.py we turn off autograd with something like torch.grad....
@hkchengrex Yes, you are right. The cause of the problem was the fact that I am using torch.set_grad_enabled(False) in load_on_device function, but load_on_device and predict functions run in different threads, so even through I use torch.set_grad_enabled(False) in my load_on_device function, it has no effect on predict function since it is being used in a different thread. I was unaware of the fact that these functions are running in different threads because I didn't have full understanding of legacy code I was using for my web app. Now it all makes sense. Thank you for help and great neural network, good luck!
Hi! Thanks for great architecture! I am coding a web application based on XMem and I am facing CUDA out of memory error when tracking on 40+ frames. My GPU has 24 GB memory. My video resolution is quite high (1920 x 1080), so I tried interpolating input mask and frames to lower resolution. It helped (without resizing I was able to track on only 5 frames, with resizing I am able to track on ~35 frames now). But it is written in your paper that it is possible to track even on 1000 frames. Can you please share memory distribution algorithms to make tracking on big amount of frames available?
Here is my code for loading model on GPU:
Here is my code for prediction:
What am I doing wrong? Why I am unable to track on more than 35 frames even with 24 GB GPU?