yolov5:RuntimeError: CUDA out of memory.

created at 08-26-2022 views: 12

problem

I encountered a problem today. The code that can be tested normally before is getting an error when testing:

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

solution

I am getting the error while debugging the test test file. Since it is directly imported into the trained model, there is no need to perform backpropagation again. So add the following statement before the forward pass or add where the error occurs:

with torch.no_grad():

I added it to the very beginning of the image loop reading

created at:08-26-2022
edited at: 08-26-2022: