记录yolov5更改backbone为ShuffleBlock网络迁移训练出错问题以及解决方法

2023-11-02

前言:最近在学习yolov5,记录一些报错

1. 张量不对

Sizes of tensors must match except in dimension 1. Expected size 16 but got size 8 for tensor number 1 in the list.

报错信息如下:

Traceback (most recent call last):
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-1475e912e0b9>", line 1, in <module>
    runfile('I:/GraduationProject/yolov5-5.0-sniperitf798/train.py', wdir='I:/GraduationProject/yolov5-5.0-sniperitf798')
  File "I:\DevSoftware\Python\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "I:\DevSoftware\Python\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "I:/GraduationProject/yolov5-5.0-sniperitf798/train.py", line 543, in <module>
    train(hyp, opt, device, tb_writer)
  File "I:/GraduationProject/yolov5-5.0-sniperitf798/train.py", line 88, in train
    model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\models\yolo.py", line 93, in __init__
    m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))])  # forward
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\models\yolo.py", line 123, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\models\yolo.py", line 139, in forward_once
    x = m(x)  # run
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\models\common.py", line 210, in forward
    return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 16 but got size 8 for tensor number 1 in the list.

初步估计是模型网络结构出了问题。
下面是报错的网络结构:

backbone:
  # [from, number, module, args]
  # Shuffle_Block: [out, stride]
  [[ -1, 1, conv_bn_relu_maxpool, [ 32 ] ], # 0-P2/4
   [ -1, 1, Shuffle_Block, [ 128, 2 ] ],  # 1-P3/8
   [ -1, 3, Shuffle_Block, [ 128, 1 ] ],  # 2
   [ -1, 1, Shuffle_Block, [ 256, 2 ] ],  # 3-P4/16
   [ -1, 7, Shuffle_Block, [ 256, 1 ] ],  # 4
   [ -1, 1, Shuffle_Block, [ 512, 2 ] ],  # 5-P5/32
   [ -1, 3, Shuffle_Block, [ 512, 1 ] ],  # 6
   [ -1, 1, Shuffle_Block, [ 1024, 2 ] ],  # 7-P6/64
#   [ -1, 3, Shuffle_Block, [ 1024, 1 ] ],  # 8
  ]

# YOLOv5 v5.0 head
head:
  [[-1, 1, Conv, [512, 1, 1]], # 7
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],# 8
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4 # 9
   [-1, 3, C3, [512, False]],  # 10

   [-1, 1, Conv, [256, 1, 1]], # 11
   [-1, 1, nn.Upsample, [None, 2, 'nearest']], # 12
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3 # 13
   [-1, 3, C3, [256, False]],  # 14 (P3/8-small)

   [-1, 1, Conv, [256, 3, 2]], # 15
   [[-1, 14], 1, Concat, [1]],  # cat head P4 # 16
   [-1, 3, C3, [512, False]],  # 17(P4/16-medium)

   [-1, 1, Conv, [512, 3, 2]],# 18
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 20 (P5/32-large)

   [[15, 18, 21], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

解决方法:在backbone网络末尾加上了Conv,spp,c3网络

# YOLOv5  backbone
backbone:
  # [from, number, module, args]
  # Shuffle_Block: [out, stride]
  [[ -1, 1, conv_bn_relu_maxpool, [ 32 ] ], # 0-P2/4
   [ -1, 1, Shuffle_Block, [ 128, 2 ] ],  # 1-P3/8
   [ -1, 3, Shuffle_Block, [ 128, 1 ] ],  # 2
   [ -1, 1, Shuffle_Block, [ 256, 2 ] ],  # 3-P4/16
   [ -1, 7, Shuffle_Block, [ 256, 1 ] ],  # 4
   [ -1, 1, Shuffle_Block, [ 512, 2 ] ],  # 5-P5/32
   [ -1, 3, Shuffle_Block, [ 512, 1 ] ],  # 6
   [ -1, 1, Conv, [ 1024, 3, 2 ] ],  # 7-P5/32
   [ -1, 1, SPP, [ 1024, [ 5, 9, 13 ] ] ],# 8
   [ -1, 3, C3, [ 1024, False ] ],  # 9
  ]

2. [WinError 1455] 页面文件太小

但是开始训练,又报新的错

train: Scanning 'VOC\labels\train' images and labels... 16551 found, 0 missing, 0 empty, 0 corrupted: 100%|██████████| 16551/16551 [00:11<00:00, 1491.29it/s]
train: New cache created: VOC\labels\train.cache
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\train.py", line 12, in <module>
    import torch.distributed as dist
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\__init__.py", line 124, in <module>
    raise err
OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.
Traceback (most recent call last):
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-1475e912e0b9>", line 1, in <module>
    runfile('I:/GraduationProject/yolov5-5.0-sniperitf798/train.py', wdir='I:/GraduationProject/yolov5-5.0-sniperitf798')
  File "I:\DevSoftware\Python\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "I:\DevSoftware\Python\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "I:/GraduationProject/yolov5-5.0-sniperitf798/train.py", line 545, in <module>
    train(hyp, opt, device, tb_writer)
  File "I:/GraduationProject/yolov5-5.0-sniperitf798/train.py", line 194, in train
    image_weights=opt.image_weights, quad=opt.quad, prefix=colorstr('train: '))
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\utils\datasets.py", line 84, in create_dataloader
    collate_fn=LoadImagesAndLabels.collate_fn4 if quad else LoadImagesAndLabels.collate_fn)
  File "I:\GraduationProject\yolov5-5.0-sniperitf798\utils\datasets.py", line 97, in __init__
    self.iterator = super().__iter__()
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 359, in __iter__
    return self._get_iterator()
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 305, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 918, in __init__
    w.start()
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "I:\EnvVariable\ML\Anaconda3\envs\pytorch\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe

出现的原因

电脑在默认情况下没有给I盘分配虚拟内存,所以将Python装在I盘的,在跑程序的时候,没有分配虚拟内存,就会遇到上面的问题。所以,只要给I盘分派虚拟内存即可。如果Python安装在C盘,更改C盘的虚拟内存的值,调大些。

解决方法

  1. 查找:查看高级系统设置
    在这里插入图片描述
  2. 进行如下图的操作
    在这里插入图片描述
  3. 重新启动计算机,重新运行程序

3. MP: Hint This means that multiple copies of the OpenMP runtime have been linked into the

解决上面一二问题开始出现新的问题,具体报错如下:

train: Scanning 'VOC\labels\train.cache' images and labels... 16551 found, 0 missing, 0 empty, 0 corrupted: 100%|██████████| 16551/16551 [00:00<?, ?it/s]
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
Scanning images:   0%|          | 0/4952 [00:00<?, ?it/s]OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
val: Scanning 'VOC\labels\val' images and labels... 4952 found, 0 missing, 0 empty, 0 corrupted: 100%|██████████| 4952/4952 [00:05<00:00, 846.03it/s]
val: New cache created: VOC\labels\val.cache
Plotting labels... 
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

解决方法:
在train.py开头添加以下代码:

##OMP报错
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'

参考:
彻底解决pycharm中: OSError: [WinError 1455] 页面文件太小,无法完成操作的问题–亲测

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

记录yolov5更改backbone为ShuffleBlock网络迁移训练出错问题以及解决方法 的相关文章

随机推荐

  • 深入剖析Kubernetes之资源模型和GPU 管理

    文章目录 资源模型 QoS 模型 GPU 管理 资源模型 在 Kubernetes 里 Pod 是最小的原子调度单位 这也就意味着 所有跟调度和资源管理相关的属性都应该是属于 Pod 对象的字段 而这其中最重要的部分 就是 Pod 的 CP
  • OpenCV机器视觉-形态学变换

    形态学变换 膨胀与腐蚀 形态学变化是基于图像形状的一些简单操作 操作对象一般是二值图像 需要两个输入 一个是我们的原图 另一个是3x3的结构元素 内核 决定了膨胀操作的本质 常见的操作是图像的膨胀和腐蚀 以及他们的进阶操作注入Opening
  • 运放单电源应用中的偏置

    单电源还是双电源 汽车和水上设备等应用中的电池供电型运算放大器仅有一个电源可用 计算机等其他应用虽然可用交流电源供电 但仍然只有一个单极性电源 如5V 或12V 直流电源 因而在实际操作中 往往需要通过单极性电源来驱动运算放大器 但单电源模
  • Linux Tensorflow2.0安装

    安装Tensorflow2 0 conda update conda pip install tf nightly gpu 2 0 preview conda install https mirrors tuna tsinghua edu
  • ES - 使用ES客户端来操作搜索引新

    1 导入需要的pom
  • ES 21 - 通过 Elasticsearch 实现聚合检索 (分组统计)

    目录 1 普通聚合分析 1 1 直接聚合统计 1 2 先检索 再聚合 1 3 扩展 fielddata和keyword的聚合比较 2 嵌套聚合 2 1 先分组 再聚合统计 2 2 先分组 再统计 最后排序 2 3 先分组 组内再分组 然后统
  • 【代码质量】C++代码质量扫描主流工具深度比较

    本文由腾讯WeTest团队提供 未经授权严禁转载 更多资讯可直接戳链接查看 http wetest qq com lab 微信号 TencentWeTest 文 张蓓 引言 静态代码分析是指无需运行被测代码 通过词法分析 语法分析 控制流
  • 199页Python保姆级指南,内容全面简洁易懂,超实用的经典教程

    Python是一种通用的多范型开源计算机编程语言 它应用于独立编程和各种各样的脚本制作 是世界上最被广泛应用的编程语言之一 近日 Towards AI 分析了多个在线职业门户网站上 3000 多个数据科学职位的发布情况 以此进行了招聘趋势层
  • uni-app + SpringBoot +stomp 支持websocket 打包app

    文章目录 一 概述 二 配置 1 后端配置 2 uni app app端 3 使用 一 概述 websocket 协议是在http 协议的基础上的升级 通过一次http 请求建立长连接 转而变为TCP 的全双工通信 而http 协议是一问一
  • 基于powerlevel10k的mac terminal,速度超快(无需oh-my-zsh)

    ZSH 安装 一般mac最新的系统都自带zsh命令 只需 chsh s bin zsh 切换到zsh命令环境 这个环境对bash命令兼容 如果你之前配置过bash的环境 可以在 zshrc里面添加 最好是配置完terminal的主题后加 因
  • 华为OD机试真题- 篮球比赛-2023年OD统一考试(B卷)

    题目描述 篮球 5V5 比赛中 每个球员拥有一个战斗力 每个队伍的所有球员战斗力之和为该队伍的总体战斗力 现有10个球员准备分为两队进行训练赛 教练希望2个队伍的战斗力差值能够尽可能的小 以达到最佳训练效果 给出10个球员的战斗力 如果你是
  • 嘿!不备案不要HTTPS!小程序请求任意网站黑科技来了!

    顶着被 封 的危险 我要偷偷告诉你一个目前还没 公布 的黑科技 方法原创研发 并在实际项目中得到了很好的使用体验 好 认真往下看 我将会告诉你一个非常好玩 实用 黑科技的技能 这将让你扩展到更多小程序开发思路 从而实现之前无法实现的功能 来
  • php查询对象是否有某个属性可用,JavaScript 判断对象中是否有某属性的常用方法...

    判断对象中是否有某属性的常见方式总结 不同的场景要使用不同的方式 一 点 或者方括号 通过点或者方括号可以获取对象的属性值 如果对象上不存在该属性 则会返回undefined 当然 这里的 不存在 指的是对象自身和原型链上都不存在 如果原型
  • 报错Failed to load config “prettier“ to extend from.两步解决方案

    解决方案 1 进入项目根目录 npm i eslint prettier eslint eslint config prettier save dev 原因 I just had this error I was manually inst
  • SQLITE源码剖析

    http www iteye com blogs subjects deepfuture
  • 走进首个通用无代码开发平台—iVX

    目录 1 iVX简介 首个 通用 无代码 开发平台 应用可移植特性 2 iVX三大属性 iVX的语言属性 iVX的云属性 云原生 iVX的工具属性 3 iVX两大能力 代码生成能力 图灵完备 的逻辑能力 4 iVX能开发哪些应用 webAp
  • 离散化算法

    文章目录 离散化模板 巩固练习 电影 区间和 金发姑娘和 N 头牛 粉刷栅栏 线段覆盖 逆序对 程序自动分析 基本介绍 离散化 把无限空间中有限的个体映射到有限的空间中去 以此提高算法的时空效率 通俗的说 离散化是在不改变数据相对大小的条件
  • Flutter开发:Flutter UI之弹窗系列

    import dart io import package flutter material dart import package flutter services dart import package flutter app demo
  • [764]tmux简介及使用教程

    tmux是一个开源工具 用于在一个终端窗口中运行多个终端会话 它可以减少过多的打开终端控制台 tmux的源码在 https github com tmux tmux 它的License是BSD Tmux 是一个终端复用器 terminal
  • 记录yolov5更改backbone为ShuffleBlock网络迁移训练出错问题以及解决方法

    前言 最近在学习yolov5 记录一些报错 1 张量不对 Sizes of tensors must match except in dimension 1 Expected size 16 but got size 8 for tenso