牛奔推太极
2021-09-02 15:24
采纳率: 0%
浏览 24
已结题

Pytorch 在windows电脑上运行LSTM for batch, data in enumerate(train_loader):报错

Pytorch 在windows电脑上运行 for batch, data in enumerate(train_loader):报错

#开始循环
for epoch in range(num_epochs):
train_loss = []

#开始遍历加载器中的数据

for batch, data in enumerate(train_loader):
#batch 为数字 表示已经进行了第几个batch
#data 为一个二元组,分别存储了一条数据记录的输入和标签
#每个数据的第一个维度都是 batch_size = 30 的数组

报错如下:

Traceback (most recent call last):
File "", line 1, in
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "D:\AZ\anaconda\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "D:\AZ\anaconda\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "D:\AZ\anaconda\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "d:\BC\lstmssc012.py", line 107, in
for batch, data in enumerate(train_loader):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 279, in iter
return _MultiProcessingDataLoaderIter(self)
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 719, in init
w.start()
File "D:\AZ\anaconda\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

<torch.utils.data.dataloader.DataLoader object at 0x00000165BE9C6FA0>
Traceback (most recent call last):
File "", line 1, in
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "D:\AZ\anaconda\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "D:\AZ\anaconda\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "D:\AZ\anaconda\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "d:\BC\lstmssc012.py", line 107, in
for batch, data in enumerate(train_loader):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 279, in iter
return _MultiProcessingDataLoaderIter(self)
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 719, in init
w.start()
File "D:\AZ\anaconda\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

<torch.utils.data.dataloader.DataLoader object at 0x000001C4529D6FA0>
Traceback (most recent call last):
File "", line 1, in
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "D:\AZ\anaconda\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "D:\AZ\anaconda\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "D:\AZ\anaconda\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "d:\BC\lstmssc012.py", line 107, in
for batch, data in enumerate(train_loader):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 279, in iter
return _MultiProcessingDataLoaderIter(self)
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 719, in init
w.start()
File "D:\AZ\anaconda\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

<torch.utils.data.dataloader.DataLoader object at 0x000002660CA56FA0>
Traceback (most recent call last):
File "", line 1, in
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "D:\AZ\anaconda\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "D:\AZ\anaconda\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "D:\AZ\anaconda\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "d:\BC\lstmssc012.py", line 107, in
for batch, data in enumerate(train_loader):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 279, in iter
return _MultiProcessingDataLoaderIter(self)
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 719, in init
w.start()
File "D:\AZ\anaconda\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "D:\AZ\anaconda\lib\multiprocessing\popen_spawn_win32.py", line 45, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "D:\AZ\anaconda\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

Traceback (most recent call last):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 761, in _try_get_data
data = self._data_queue.get(timeout=timeout)
File "D:\AZ\anaconda\lib\multiprocessing\queues.py", line 108, in get
raise Empty
_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:/BC/lstmssc012.py", line 107, in
for batch, data in enumerate(train_loader):
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 345, in next
data = self._next_data()
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 841, in _next_data
idx, data = self._get_data()
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 808, in _get_data
success, data = self._try_get_data()
File "D:\AZ\anaconda\lib\site-packages\torch\utils\data\dataloader.py", line 774, in _try_get_data
raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 23168, 25056, 2484, 25292) exited unexpectedly

  • 收藏

2条回答 默认 最新

  • 牛奔推太极 2021-09-02 15:35

    代码是按照PYtorch 深度学习原理与实战 上搬下来的,我运行就报错

    打赏 评论
  • 有问必答小助手 2021-09-06 10:25

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


    因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    打赏 评论

相关推荐 更多相似问题