如何解决为什么我无法在我的数据集中训练YOLOv5?
我正在尝试使用自定义数据集在Jupyter笔记本上训练YOLOv5模型。数据集是face mask detection数据集,包含带有/不带有口罩的人物图像。我已经将注释转换为YOLO格式,并且我相信我已经编辑了所有必要的文件以反映类的数量(3:无遮罩,正确佩戴的遮罩,错误佩戴的遮罩)以及训练/验证文件的位置。 / p>
这样做之后,我执行了以下命令:
!python train.py --img 256 --batch 8 --epochs 30 --data ./data/facemask.yaml --cfg ./models/yolov5s.yaml --weights yolov5s.pt --device 0
但我收到此错误:
Traceback (most recent call last):
File "./yolov5-master/train.py",line 404,in <module>
train(hyp)
File "./yolov5-master/train.py",line 79,in train
model = Model(opt.cfg).to(device)
File "/storage/facemask/yolov5-master/models/yolo.py",line 64,in __init__
m.stride = torch.tensor([64 / x.shape[-2] for x in self.forward(torch.zeros(1,ch,64,64))]) # forward
File "/storage/facemask/yolov5-master/models/yolo.py",line 91,in forward
return self.forward_once(x,profile) # single-scale inference,train
File "/storage/facemask/yolov5-master/models/yolo.py",line 108,in forward_once
x = m(x) # run
File "/opt/conda/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/module.py",line 722,in _call_impl
result = self.forward(*input,**kwargs)
File "/storage/facemask/yolov5-master/models/yolo.py",line 28,in forward
x[i] = x[i].view(bs,self.na,self.no,ny,nx).permute(0,1,3,4,2).contiguous()
RuntimeError: shape '[1,8,8]' is invalid for input of size 8192
我发现YOLOv3的帖子提到yolov3-spp.cfg文件中的过滤器数量应该更新,但是我不认为YOLOv5有任何此类文件。
有人有见识吗?
对于可重复性,重新格式化的数据集和所有补充文件均可用here
解决方法
尝试在 yolo.py 中添加 x[i]=self.m[i](x[i])
第 28 行。像这样
def forward(self,x):
# x = x.copy() # for profiling
z = [] # inference output
self.training |= self.export
for i in range(self.nl):
#[1,128,80,80]
bs,_,ny,nx = x[i].shape # x(bs,255,20,20) to x(bs,3,85)
x[i] =self.m[i](x[i]) # **add this code here**
x[i] = x[i].view(bs,self.na,self.no,nx).permute(0,1,4,2).contiguous()
如果这不起作用,那么您的权重可能有问题,请尝试使用与 yolov5 版本匹配的 *.pt 文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。