初次跑yolo5遇到的一些问题

1.

ImportError: cannot import name COMMON_SAFE_ASCII_CHARACTERS‘ from charset-normalizerconstant‘

这个报错可能是由于charset_normalizer模块的版本问题引起的。尝试更新charset_normalizer模块到最新版本,或者使用较旧的版本,看看是否可以解决问题。您可以尝试以下命令更新模块:

pip install --upgrade charset-normalizer

如果仍然无法解决问题,请尝试卸载charset_normalizer模块,然后重新安装:

pip uninstall charset-normalizer
pip install charset-normalizer

2.

RuntimeError: result type Float can‘t be cast to the desired output type __int64

云兄

 将loss.py中gain = torch.ones(7, device=targets.device)改为gain = torch.ones(7, device=targets.device).long()即可。原因是新版本的torch无法自动执行此转换,旧版本torch可以。

loss.py在utils文件夹下,ctrl+f搜索gain,找到gain = torch.ones(7, device=targets.device),将其修改为gain = torch.ones(7, device=targets.device).long(),问题解决

在这里插入图片描述

3 .

 4.

在这里插入图片描述

从图中可以看出用的是volov5-5.0版本,这里提到了Can't get attribute 'SPPF' on <module 'models.common',所以可以去volov5-6.0版本里面的model/common.py里面去找到这个SPPF类,然后copy进model/common.py文件中,如下:
在这里插入图片描述

 按照图示,导入一个warnings的包即可

5.

错误:RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3

在这里插入图片描述

解决方法:https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt

下载之后替换yolov5文件中的yolov5s.pt

6.

解决方法:首先找到datasets.py这个py文件。

      打开文件,找到第279行代码,给两个url参数加上str就可以了,如图所示,就可以完美运行电脑的摄像头了

7.

标注的时候方便点

开cmd命令终端(快捷键:win+R)。进入到刚刚创建的这个VOC2007路径(这个很重要,涉及到能不能利用predefined_classes.txt 这个txt文件中定义的类别,我在这里卡了很久,一度以为不能显示txt文件中定义的类别是我安装有问题)。执行如图中的命令进入到VOC2007路径下(每个人的路径都不一样,按个人的路径去写)如下图所示:可以看到进入到相应的目录了。
 

   输入如下的命令打开labelimg。这个命令的意思是打开labelimg工具;打开JPEGImage文件夹,初始化predefined_classes.txt里面定义的类。

labelimg JPEGImages predefined_classes.txt

8

.UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument.

解决方法:

根据报错的提示点击上述报错提示的蓝色字体,然后跳转到相应的functional.py文件

根据查找ctr+F快捷键输入:

_VF.meshgrid 

找到对应的位置,然后出现找到下面图片所展示的位置:

加上如下代码 indexing = 'ij'

9

Dataset autodownload failure

解决办法:把下载的coco128数据集和项目yolov5-5.0放在同一级目录中

10

报错:AttributeError: ‘Upsample’ object has no attribute ‘recompute_scale_factor’

 2.将原代码(153-154行)修改为如下所示(155行):

return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)

11

RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.


   def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
        # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
        m = self.model[-1]  # Detect() module
        for mi, s in zip(m.m, m.stride):  # from
            b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
            b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
            b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
            mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

修改为

  def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
        # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
        m = self.model[-1]  # Detect() module
        for mi, s in zip(m.m, m.stride):  # from
            b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
            with torch.no_grad():
                b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
                b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
            mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)    def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
        # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
        m = self.model[-1]  # Detect() module
        for mi, s in zip(m.m, m.stride):  # from
            b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
            with torch.no_grad():
                b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
                b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
            mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

12

训练不起来可以在开头加上

import os
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
import json
from git.repo import Repo
from git.repo.fun import is_git_dir

import os
os.environ["KMP_DUPLICATE_LIB_OK"]  =  "TRUE"

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值