RuntimeError: CUDA out of memory. Tried to allocate 754.00 MiB (GPU 0; 2.00 GiB total capacity; 1.21 GiB already allocated ...)

Nika Maisuradze picture Nika Maisuradze · Dec 12, 2019 · Viewed 10.1k times · Source

I'm trying transform video into high FPS footage using Super-SloMo https://www.youtube.com/watch?v=mXwXtIiOjRA&t=329s

and when I run this process in Anaconda prompt it stops after about 30 seconds and shows me this "RuntimeError: CUDA out of memory. Tried to allocate 754.00 MiB (GPU 0; 2.00 GiB total capacity; 1.21 GiB already allocated; 144.74 MiB free; 10.06 MiB cached)"

I don't really know what is going there, and I have few questions about that.

My Laptop specs: intel i3-7100u with Gefroce 920mx dedicated graphics card

  1. so when I look at task manager during this process only CPU is loaded and Gpu-s are not, so is it correct? like maybe GPU can process thoes things?
  2. process stops and writes "RuntimeError: CUDA out of memory. Tried to allocate 754.00 MiB (GPU 0...) Can i somehow make cuda to use GPU 1 instead of GPU 0? maybe that would help.

as I saw in video I linked, this process can be done with processor or nvidia grapics card, and doing it with nvidia would be much faster.

This is what it looks when it is running

This is when it stops

code is here:

(base) C:\Users\Nika>cd /d D:\SlowMo\SuperSloMo

(base) D:\SlowMo\SuperSloMo>python video_to_slomo.py --ffmpeg D:\SlowMo\ffmpeg\bin\ --video D:\SlowMo\Input\Rotate.mp4 --sf 4 --checkpoint D:\SlowMo\SuperSloMo\SuperSloMo.ckpt --fps 120 --output D:\SlowMo\Output\Rotate120.mkv
D:\SlowMo\ffmpeg\bin\ffmpeg -i D:\SlowMo\Input\Rotate.mp4 -vsync 0 tmpSuperSloMo\input/%06d.png
ffmpeg version N-94156-g93a73df54d Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190621
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 30.100 / 56. 30.100
  libavcodec     58. 53.101 / 58. 53.101
  libavformat    58. 28.101 / 58. 28.101
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 56.100 /  7. 56.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\SlowMo\Input\Rotate.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    creation_time   : 2019-04-29T19:00:00.000000Z
  Duration: 00:00:04.67, start: 0.033333, bitrate: 32571 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 2880x2160 [SAR 1:1 DAR 4:3], 33772 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2019-12-08T21:30:20.000000Z
      handler_name    : VideoHandler
      encoder         : AVC Coding
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'tmpSuperSloMo\input/%06d.png':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp41isom
    encoder         : Lavf58.28.101
    Stream #0:0(und): Video: png, rgb24, 2880x2160 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2019-12-08T21:30:20.000000Z
      handler_name    : VideoHandler
      encoder         : Lavc58.53.101 png
frame=  135 fps=1.6 q=-0.0 Lsize=N/A time=00:00:04.50 bitrate=N/A speed=0.0525x
video:1337063kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
  0%|                                                       | 0/134 [00:04<?, ?it/s]
Traceback (most recent call last):
  File "video_to_slomo.py", line 217, in <module>
    main()
  File "video_to_slomo.py", line 166, in main
    flowOut = flowComp(torch.cat((I0, I1), dim=1))
  File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "D:\SlowMo\SuperSloMo\model.py", line 197, in forward
    x  = F.leaky_relu(self.conv1(x), negative_slope = 0.1)
  File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1063, in leaky_relu
    result = torch._C._nn.leaky_relu(input, negative_slope)
RuntimeError: CUDA out of memory. Tried to allocate 754.00 MiB (GPU 0; 2.00 GiB total capacity; 1.21 GiB already allocated; 144.74 MiB free; 10.06 MiB cached)

(base) D:\SlowMo\SuperSloMo>

Answer

Victoria Dochkina picture Victoria Dochkina · May 12, 2020

Please try this. It worked for me:

import torch, gc

gc.collect()
torch.cuda.empty_cache()