YOLOv5学习过程中的问题

YOLOv5学习过程中的问题

学习博客链接:目标检测–手把手教你搭建自己的YOLOv5目标检测平台

问题1

在安装requirements时出现下述错误

ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

解决方式:在requirements.txt文件中将pycocotools>=2.0 修改为pycocotools-windows>=2.0

原因:pycocotools的维护者不再提供Windows平台的支持

问题2

在运行train.py文件进行运行时出现以下错误

AssertionError: Image Not Found D:\PycharmProjects\yolov5-hat\VOCdevkit\images\train\000000

解决方式:删除存放标签目录下的train.cache和val.cache文件

原因:训练时会默认使用原有的缓存文件进行训练,由于训练集绝对路径已经更改,所以要对其进行删除,避免继续加载原有路径

问题3

最后一步训练出现

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

解决方式:找到5.0版报错的loss.py中最后那段for函数,将其整体替换为yolov5-master版中loss.py最后一段for函数即可正常运行

        for i in range(self.nl):
            anchors, shape = self.anchors[i], p[i].shape
            gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]]  # xyxy gain
 
            # Match targets to anchors
            t = targets * gain  # shape(3,n,7)
            if nt:
                # Matches
                r = t[..., 4:6] / anchors[:, None]  # wh ratio
                j = torch.max(r, 1 / r).max(2)[0] < self.hyp['anchor_t']  # compare
                # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t']  # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2))
                t = t[j]  # filter
 
                # Offsets
                gxy = t[:, 2:4]  # grid xy
                gxi = gain[[2, 3]] - gxy  # inverse
                j, k = ((gxy % 1 < g) & (gxy > 1)).T
                l, m = ((gxi % 1 < g) & (gxi > 1)).T
                j = torch.stack((torch.ones_like(j), j, k, l, m))
                t = t.repeat((5, 1, 1))[j]
                offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j]
            else:
                t = targets[0]
                offsets = 0
 
            # Define
            bc, gxy, gwh, a = t.chunk(4, 1)  # (image, class), grid xy, grid wh, anchors
            a, (b, c) = a.long().view(-1), bc.long().T  # anchors, image, class
            gij = (gxy - offsets).long()
            gi, gj = gij.T  # grid indices
 
            # Append
            indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1)))  # image, anchor, grid
            tbox.append(torch.cat((gxy - gij, gwh), 1))  # box
            anch.append(anchors[a])  # anchors
            tcls.append(c)  # class

问题4

在yolov5训练完成后,运行detect.py文件出现下述错误:

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

解决方式:

进入报错中的upsampling.py文件的line 154,修改forward函数,将

recompute_scale_factor=self.recompute_scale_factor

删除即可

原因:可能是pytorch版本问题

你可能感兴趣的:(深度学习,目标检测,python,人工智能)