在 Pytorch 1.4 中使用自定义数据集训练模型时,在看似随机的时期后会引发以下错误。
RuntimeError: Couldn't open shared file mapping: <torch_15324_2327643205>, error code: <1455>
数据集被包裹在
torch.utils.data.DataLoader
中并使用4个worker,等于物理核心的数量。
class TSNDataSet(data.Dataset):
def __init__(self, pickle_file_paths, transforms):
self.pickle_file_paths = pickle_file_paths # list with file paths to pickle files
self.dataset_size = len(pickle_file_paths)
def __getitem__(self, index):
with open(self.pickle_file_paths[index], 'rb') as f:
mffs = pickle.load(f)
return mffs, index
def __len__(self):
return self.dataset_size
了解错误的含义以及可能的解决方案是什么会很有帮助。
当 GPU 内存即将耗尽时,很可能会发生这种情况。在每个下一个纪元开始后都会观察到同样的问题。我使用具有 8GB 内存的 1070Ti 运行了批量大小为 1300 的 ImageNet 摘录。图像是从 RAM 驱动器加载的。
该问题与 torch.utils.data.DataLoader 在 enumerate 调用上执行的 collate 操作有关。
对于所附的屏幕截图,当图表显示红线并且共享内存正在使用 14+ GB 时,我的故障发生了。在批量大小减少两次后,达到 650,任务管理器显示仅使用了 2.6 GB,并且程序从一个纪元到另一个纪元都运行得很好。