RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 1.96 GiB total capacity; 1.40

跑yolov4测试demo报错

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 1.96 GiB total capacity; 1.40 GiB already allocated; 18.50 MiB free; 1.46 GiB reserved in total by PyTorch)

原因

  1. GPU还有其他进程占用显存,导致本进程无法分配到足够的显存
  2. 缓存过多,使用torch.cuda.empty_cache()清理缓存
  3. 显存不够,换块显卡吧

解决方案

测试的时候加上

with torch.no_grad():
  # test process

你可能感兴趣的:(python,ubuntu,linux)