方法一 加入过CUDA的都del掉,del后再加上torch.cuda.empty_cache()才会起效果 速度会变慢 # delete caches del img, segm, outputs, loss torch.cuda.empty_cache() 方法二* 检查验证部分有没有加with torch.no_grad(): 加入之后显存占用缓慢增加的问题得到了解决,而且不影响速度