RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB,错误记录

代码运行报这个错误:
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.93 GiB total capacity; 94.84 MiB already allocated; 21.00 MiB free; 108.00 MiB reserved in total by PyTorch)

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

加入以上代码解决了,记录下。

你可能感兴趣的:(Python,tensorflow,pytorch)