【发布时间】:2021-07-19 07:40:48
【问题描述】:
所以我有这个数据加载器,它从 hdf5 加载数据,但在我使用 num_workers>0 时意外退出(它在 0 时工作正常)。更奇怪的是,它适用于 google colab 上的更多工作人员,但不适用于我的计算机。 在我的电脑上出现以下错误:
Traceback(最近一次调用最后一次): _try_get_data 中的文件“C:\Users\Flavio Maia\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py”,第 986 行 数据 = self._data_queue.get(timeout=timeout) 文件“C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\multiprocessing\queues.py”,第 105 行,在 get 提高空 _queue.Empty
上述异常是以下异常的直接原因:
Traceback(最近一次调用最后一次): 文件“”,第 2 行,在 下一个中的文件“C:\Users\Flavio Maia\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py”,第 517 行 数据 = self._next_data() _next_data 中的文件“C:\Users\Flavio Maia\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py”,第 1182 行 idx,数据 = self._get_data() _get_data 中的文件“C:\Users\Flavio Maia\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py”,第 1148 行 成功,数据 = self._try_get_data() 文件“C:\Users\Flavio Maia\AppData\Roaming\Python\Python37\site-packages\torch\utils\data\dataloader.py”,第 999 行,在 _try_get_data raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e RuntimeError: DataLoader worker (pid(s) 12332) 意外退出
另外,我的 getitem 函数是:
def __getitem__(self,index):
desired_file = int(index/self.file_size)
position = index % self.file_size
h5_file = h5py.File(self.files[desired_file], 'r')
image = h5_file['Screenshots'][position]
rect = h5_file['Rectangles'][position]
numb = h5_file['Numbers'][position]
h5_file.close()
image = torch.from_numpy(image).float()
rect = torch.from_numpy(rect).float()
numb = torch.from_numpy( np.asarray(numb) ).float()
return (image, rect, numb)
有谁知道是什么导致了这个空队列?
【问题讨论】:
标签: pytorch multiprocessing hdf5 dataloader