首页 新闻 会员 周边 捐助

AttributeError: Can't pickle local object 'SubPolicy.__init__.<locals>.<lambda>

0
[已解决问题] 解决于 2024-07-07 09:11

深度学习训练过程报错:

Traceback (most recent call last):
  File "D:\workspace\out-in-noise-lt\method\method2.py", line 280, in <module>
    main_workers()
  File "D:\workspace\out-in-noise-lt\method\method2.py", line 250, in main_workers
    train2(epoch, labeled_loader, unlabeled_loader, model, criterion_ce, optimizer, scaler,
  File "D:\workspace\out-in-noise-lt\method\method2.py", line 161, in train2
    unlabeled_loader_iter = iter(unlabeled_loader)
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 439, in __iter__
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: Ran out of input
    return self._get_iterator()
           ^^^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 387, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 1040, in __init__
    w.start()
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
                  ^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\context.py", line 337, in _Popen
    return Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\popen_spawn_win32.py", line 95, in __init__
    reduction.dump(process_obj, to_child)
  File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'SubPolicy.__init__.<locals>.<lambda>'

运行环境:

# Name                    Version                   Build  Channel
pytorch                   2.3.1           py3.12_cuda12.1_cudnn8_0    pytorch
October-的主页 October- | 初学一级 | 园豆:164
提问于:2024-07-07 09:00
< >
分享
最佳答案
1

数据量不是特别大,可以考虑使用单进程模式加载数据,避免序列化问题,可以设置Dataloader的num_workers=0

October- | 初学一级 |园豆:164 | 2024-07-07 09:01

我的num_works就是为0,依旧有这个错误,怎么办

方方f啊 | 园豆:200 (初学一级) | 2024-12-05 14:42

@方方f啊: 汇报下你的报错信息

October- | 园豆:164 (初学一级) | 2024-12-05 14:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册