运行时错误:CUDA 内存不足.已尝试分配 754.00 MiB(GPU 0;2.00 GiB 总容量;已分配 1.21



我正在尝试使用Super-SloMo将视频转换为高FPS素材 https://www.youtube.com/watch?v=mXwXtIiOjRA&t=329s

当我在 Anaconda 提示符下运行此过程时,它会在大约 30 秒后停止并向我显示此"运行时错误:CUDA 内存不足。已尝试分配 754.00 MiB(GPU 0;2.00 GiB 总容量;已分配 1.21 GiB;144.74 MiB 可用;10.06 MiB 缓存(">

我真的不知道那里发生了什么,我对此几乎没有疑问。

我的笔记本电脑规格:英特尔i3-7100U与Gefroce 920MX专用显卡

  1. 所以当我在此过程中查看任务管理器时,只加载了 CPU 而没有加载 GPU-s,所以它是否正确? 就像也许 GPU 可以处理这些事情一样?
  2. 进程停止并写入"运行时错误:CUDA 内存不足。已尝试分配 754.00 MiB (GPU 0...(我可以以某种方式使 cuda 使用 GPU 1 而不是 GPU 0 吗?也许这会有所帮助。

正如我在链接的视频中看到的那样,此过程可以使用处理器或 NVIDIA Grapics 卡完成,使用 nvidia 完成会快得多。

这是它运行时的样子

这是它停止的时候

代码在这里:

(base) C:UsersNika>cd /d D:SlowMoSuperSloMo
(base) D:SlowMoSuperSloMo>python video_to_slomo.py --ffmpeg D:SlowMoffmpegbin --video D:SlowMoInputRotate.mp4 --sf 4 --checkpoint D:SlowMoSuperSloMoSuperSloMo.ckpt --fps 120 --output D:SlowMoOutputRotate120.mkv
D:SlowMoffmpegbinffmpeg -i D:SlowMoInputRotate.mp4 -vsync 0 tmpSuperSloMoinput/%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:SlowMoInputRotate.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 'tmpSuperSloMoinput/%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:ProgramDataAnaconda3libsite-packagestorchnnmodulesmodule.py", line 541, in __call__
result = self.forward(*input, **kwargs)
File "D:SlowMoSuperSloMomodel.py", line 197, in forward
x  = F.leaky_relu(self.conv1(x), negative_slope = 0.1)
File "C:ProgramDataAnaconda3libsite-packagestorchnnfunctional.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:SlowMoSuperSloMo>

请尝试一下。它对我有用:

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

最新更新