Bringing-Old-Photos-Back-to-Life: RuntimeError: CUDA out of memory.

I get the following error: RuntimeError: CUDA out of memory. Tried to allocate 88.00 MiB (GPU 0; 5.80 GiB total capacity; 4.14 GiB already allocated; 154.56 MiB free; 4.24 GiB reserved in total by PyTorch)

Is there a way to allocate more memory? I do not get why 4.14Gb are already allocated.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 20
  • Comments: 21 (2 by maintainers)

Most upvoted comments

I just ran into the same issue, for me it was - RuntimeError: CUDA out of memory. Tried to allocate 734.00 MiB (GPU 0; 10.74 GiB total capacity; 7.82 GiB already allocated; 195.75 MiB free; 9.00 GiB reserved in total by PyTorch)

I was able to fix with the following steps:

  1. In run.py I changed test_mode to Scale / Crop to confirm this actually fixes the issue -> the input picture was too large.
  2. I rewrote data_transforms in test.py to scale not to 256px max dimension, but rather to 1.3Mpx total area (seems to be the max capacity of my card).
  3. The for-loop in the end of test.py seems to be leaking GPU memory (1st iteration worked while 2nd, 3rd… didn’t). I extracted the loop contents to a new function to let python garbage-collect temporary variables.

I would still love to be able to process full resolution pictures if anyone has a solution.

A simply walkaround is to reduce your image size > 640x480. Evenmore if you are trying to use ‘–with-scratches’ this will increase dramatically use of GPU memory. But it is a pitty to have to downscale your photo. With DeOldify it never happens.

first stage

Hello, we just redesign the network to support high-resolution images. Welcome to have a try. You can run the code with arguments:

python run.py --input_folder [test_image_folder_path] \
              --output_folder [output_path] \
              --GPU 0 \
              --with_scratch \
              --HR

same error: GPU: Titan X 12GB cuda memory,still not working input_image size :~1500 x ~ 2000 pixel collapse at stage 1 is it possible to modify some params to make it working?

@grenaud try to use NVtop, just to get a full view what is using your GPU and how much resource is using