ForkingPickler(file, protocol).dump(obj) TypeError: can‘t pickle Environment objects

简介: ForkingPickler(file, protocol).dump(obj) TypeError: can‘t pickle Environment objects

问题描述

在win系统下复现SPSR代码出现这种错误,查询资料发现是windows系统的问题。

解决方案:

因为windows操作系统的原因,在Windows中,多进程multiprocessing使用的是序列化pickle来在多进程之间转移数据,而socket对象是不能被序列化的,但是在linux操作系统上却没问题,因为在linux上多进程multiprocessing使用的是fork,所以在windows上可以改用多线程。因为网络通信属于io密集型的操作,对cpu计算要求不高,不用多进程,用多线程就行。

num_workers=0,记得无论是参数设置还是数据集读取处理的代码,都要重新设置。

loader = torch.utils.data.DataLoader(dataset=dataset,
                                              batch_size=self.batch,
                                              shuffle=self.shuf,
                                              num_workers=0,
                                              drop_last=True)
 
parser.add_argument('--num_workers', type=int, default=0)

还有一些其他的解决方案:python3 PicklingError: Can't pickle  at......> attribute lookup  on __main_can't pickle  at 0x000001ed8215d-CSDN博客

参考:成功解决can‘t pickle Environment objects和Ran out of input_forkingpickler(file, protocol).dump(obj) typeerror-CSDN博客

目录
相关文章
Cannot read properties of undefined (reading ‘resetFields‘)“
Cannot read properties of undefined (reading ‘resetFields‘)“
259 0
|
3月前
|
PyTorch 算法框架/工具 Python
Traceback (most recent call last):WARNING: Dataset not found, nonexistent paths:
这篇文章描述了在使用YOLOv5进行训练时遇到的"Dataset not found"错误,分析了可能的原因,包括网络连接问题和数据集路径配置错误,并提供了相应的解决方法,如检查网络设置和确认数据集文件的存放位置。
Traceback (most recent call last):WARNING: Dataset not found, nonexistent paths:
成功解决ForkingPickler(file, protocol).dump(obj) TypeError: can't pickle Environment objects
成功解决ForkingPickler(file, protocol).dump(obj) TypeError: can't pickle Environment objects
成功解决ForkingPickler(file, protocol).dump(obj) TypeError: can't pickle Environment objects
|
4月前
|
开发者 Python
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
【Python】已解决:TypeError: descriptor ‘index‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
106 0
|
4月前
|
Python
【Python】已解决:TypeError: write._Log() takes 0 positional arguments but 1 was given
【Python】已解决:TypeError: write._Log() takes 0 positional arguments but 1 was given
90 0
|
6月前
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
817 0
|
6月前
报错:cannot read properties of undefined(reading ‘forEach‘)
报错:cannot read properties of undefined(reading ‘forEach‘)
480 1
报错:cannot read properties of undefined(reading ‘forEach‘)
|
6月前
|
JavaScript
【报错】:Cannot read properties of undefined (reading ‘prototype‘)
【报错】:Cannot read properties of undefined (reading ‘prototype‘)
358 0
|
6月前
|
测试技术
ERROR [karma]_ TypeError_ Cannot read property 'unmask' of undefine
ERROR [karma]_ TypeError_ Cannot read property 'unmask' of undefine
52 0
|
6月前
|
JavaScript
Cannot read properties of undefined (reading ‘install‘) TypeError: Cannot read properties of……
Cannot read properties of undefined (reading ‘install‘) TypeError: Cannot read properties of……