【问题标题】:Dataloader worker exited unexpectedly while running on Visual Studio. But runs okay on Google Colab在 Visual Studio 上运行时,Dataloader 工作人员意外退出。但在 Google Colab 上运行良好
【发布时间】: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


    【解决方案1】:

    Windows 无法处理 num_workers > 0 。您可以将其设置为 0,这很好。什么也应该起作用:将所有训练/测试脚本放在train/test() 函数中并在if __name__ == "__main__": 下调用它 比如这样:

    class MyDataLoder(torch.utils.data.Dataset):
        train_set = create_dataloader()
        . . . 
    
    def train():
        test_set = create_dataloader()
        . . .
    
    def test():
        . . .
    
    if __name__ == "__main__":
        train()
        test()
    

    【讨论】:

    • 我最终通过使用 linux 解决了这个问题,但我没有遇到问题。但现在如果我需要在 Windows 上运行,我知道该怎么做。谢谢!
    猜你喜欢
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多