yolov5测试报错:RuntimeError: CUDA out of memory.

今天遇到一个问题,之前可以正常测试的代码,今天进行测试时报错:

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 7.93 GiB
 total capacity; 6.55 GiB already allocated; 52.56 MiB free; 6.66 GiB reserved in 
total by PyTorch) If reserved memory is >> allocated memory try setting 
max_split_size_mb to avoid fragmentation.  See documentation for Memory Management
 and PYTORCH_CUDA_ALLOC_CONF

然后通过网络搜索,有解决办法(RuntimeError: CUDA out of memory.不一定是显存不够用_柠檬也可以不酸的博客-CSDN博客)

然后我就在图片循环读取的最开始位置加入:

 with torch.no_grad():

然后问题就解决了:

 

你可能感兴趣的:(linux,目标检测,pytorch,cuda,yolov5)