【发布时间】:2021-08-13 01:56:58
【问题描述】:
我陷入了一个循环。我正在运行一个 pytorch 程序。有一个部分我不得不调整图像的大小,
def __getitem__(self, index):
part1, part2, part3, label = self.data[index]
temp = np.array(part3)
temp.resize(32,32)
img = np.stack((temp,temp,temp), axis=-1)
return img, int(label)
原始大小为 (150,312)。
当我运行此程序时,我在第二次尝试中获得了 100% 的准确度,这太好了,令人难以置信。我怀疑调整大小是导致此问题的原因。 (如果有其他可能的原因,请告诉我)因此我试图将图像大小增加到至少 128,128。但如果我确实将图像大小增加到 128,128,我会得到,
RuntimeError: CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 11.91 GiB total capacity; 10.40 GiB already allocated; 130.56 MiB free; 11.08 GiB reserved in total by PyTorch)
我尝试了几种解决方案。
1:torch.cuda.empty_cache()
2:gc.collect()
这两者都没有任何区别。
3:将图像大小减小到 64,64((40,40)没有导致任何错误但准确度为 100%) 得到了
RuntimeError: mat1 dim 1 must match mat2 dim 0
4:更改批量大小。 Batch size 32 仍然会导致 CUDA out of memory 错误,16 会导致
RuntimeError: mat1 dim 1 must match mat2 dim 0
请给我任何建议。提前谢谢你。
【问题讨论】:
-
你的模型有多大?
-
在哪里可以查到?
-
我的意思是你总共要分配多少内存?
-
请创建一个可重现的最小示例!
-
@user253751 仅 256MiB