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"