Github下载的Pytorch0.4.1的代码,linux运行没问题,转到windows出现错误!

File “D:\Anaconda3.7\lib\multiprocessing\process.py”, line 112, in start
self._popen = self._Popen(self)
File “D:\Anaconda3.7\lib\multiprocessing\context.py”, line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File “D:\Anaconda3.7\lib\multiprocessing\context.py”, line 322, in _Popen
return Popen(process_obj)
File “D:\Anaconda3.7\lib\multiprocessing\popen_spawn_win32.py”, line 89, in init
reduction.dump(process_obj, to_child)
File “D:\Anaconda3.7\lib\multiprocessing\reduction.py”, line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: can’t pickle Environment objects

出现问题原因:

多线程导致的

data_loader = data.DataLoader(dataset, batch_size, num_workers=args.num_workers,shuffle=True, collate_fn=detection_collate, pin_memory=True)
解决方法:

修改num_workers=0,即可解决。
num_workers (int, optional):
这个参数决定了有几个进程来处理data loading。0意味着所有的数据都会被load进主进程。(默认为0)

Logo

更多推荐