当前位置:网站首页>yolov5 test.py BrokenPipeError: [Errno 32] Broken pipe问题解决
yolov5 test.py BrokenPipeError: [Errno 32] Broken pipe问题解决
2022-07-22 21:28:00 【Christo3】
dataset.py
batch_size = min(batch_size, len(dataset))
nw = min([os.cpu_count() // world_size, batch_size if batch_size > 1 else 0, workers]) # number of workers
sampler = torch.utils.data.distributed.DistributedSampler(dataset) if rank != -1 else None
loader = torch.utils.data.DataLoader if image_weights else InfiniteDataLoader
# Use torch.utils.data.DataLoader() if dataset.properties will update during training else InfiniteDataLoader()
dataloader = loader(dataset,
batch_size=batch_size,
num_workers= nw,
sampler=sampler,
pin_memory=True,
collate_fn=LoadImagesAndLabels.collate_fn4 if quad else LoadImagesAndLabels.collate_fn)
return dataloader, dataset
解决办法
将loader函数中的num_workers参数设置为0num_worker的作用
1、每每轮到dataloader加载数据时:dataloader一次性创建num_worker个worker,(也可以说dataloader一次性创建num_worker个工作进程,worker也是普通的工作进程),并用batch_sampler将指定batch分配给指定worker,worker将它负责的batch加载进RAM。然后,dataloader从RAM中找本轮迭代要用的batch,如果找到了,就使用。如果没找到,就要num_worker个worker继续加载batch到内存,直到dataloader在RAM中找到目标batch。一般情况下都是能找到的,因为batch_sampler指定batch时当然优先指定本轮要用的batch。
2、num_worker设置得大,好处是寻找batch速度快,因为下一轮迭代的batch很可能在上一轮/上上一轮…迭代时已经加载好了。坏处是内存开销大,也加重了CPU负担(worker加载数据到RAM的进程是CPU复制的嘛)。num_workers的经验设置值是自己电脑/服务器的CPU核心数,如果CPU很强、RAM也很充足,就可以设置得更大些。
3、如果num_worker设为0,意味着每一轮迭代时,dataloader不再有自主加载数据到RAM这一步骤(因为没有worker了),而是在RAM中找batch,找不到时再加载相应的batch。缺点当然是速度更慢。
边栏推荐
- 局域网SDN硬核技术内幕 18 美丽新世界
- 驱动页面性能优化的3个有效策略
- Summary in the development process BaseService provides a public access service file for all controllers or services to reduce repeated injection
- 避错,常见Appium相关问题及解决方案
- Information system project managers must recite the core examination points (49) contract law
- Classes and objects (1)
- 局域网SDN技术硬核内幕 9 从软件Overlay到硬件Overlay
- FastAPI学习(二)——FastAPI+Jinjia2模板渲染网页(跳转返回渲染页面)
- CPU/GPU(CUDA)版本的 YOLOv5后处理代码
- Patrick McHardy事件对开源社区的影响
猜你喜欢

Wechat hotel reservation applet graduation project (6) opening defense ppt

【09】程序装载:“640K内存”真的不够用么?

Classes and objects (1)

Copytexture, copytoresolvetarget of UE4 engine
![[technology popularization] alliance chain layer2- on a new possibility](/img/e1/be9779eee3d3d4dcf56e103ba1d3d6.jpg)
[technology popularization] alliance chain layer2- on a new possibility

主题域模型

ETL工具(数据同步)

记一次线上SQL死锁事故:如何避免死锁?

Scala Generic 泛型类详解 - T

【刷题记录】18. 四数之和
随机推荐
4G传输模块的功能应用
用Stanford Parse(智能语言处理)去实现分词器
Wechat campus second-hand book trading applet graduation design finished product (5) assignment
【无标题】
Problems encountered in punching
FastAPI学习(二)——FastAPI+Jinjia2模板渲染网页(跳转返回渲染页面)
延伸联接边界,扩展业务范围,全面迈向智能云网2.0时代
船新 IDEA 2022.2 正式发布,新特性真香
Wechat campus second-hand book trading applet graduation design finished product (6) opening defense ppt
主题域模型
【刷题记录】18. 四数之和
Here comes the genuine Adobe software! Adobe's only genuine family bucket subscription in the world costs only 0 yuan / year
C语音实现tcp客户端和tcp服务端,Qt调用测试
CPU/GPU(CUDA)版本的 YOLOv5后处理代码
Wechat campus second-hand book trading applet graduation design finished product (7) Interim inspection report
Talk about 12 business scenarios of concurrent programming
Scala Generic 泛型类详解 - T
文件上传,服务器文件名中文乱码文件上传,服务器文件名中文乱码
Understand the domestic open source Magnolia license series agreement in simple terms
局域网SDN技术硬核内幕 8 从二层交换到三层路由