北京网站建设 shwl,网站建设教程多少钱,app排名优化,排名seo公司哪家好小白刚开始学习YOLOv5#xff0c;跟随老哥的步骤走了一遍目标检测--手把手教你搭建自己的YOLOv5目标检测平台 最后训练最后一步出现RuntimeError: result type Float can‘t be cast to the desired output type __int64报错
解决方法#xff1a;找到5.0版报错的loss.py中最… 小白刚开始学习YOLOv5跟随老哥的步骤走了一遍目标检测--手把手教你搭建自己的YOLOv5目标检测平台 最后训练最后一步出现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].shapegain[2:6] torch.tensor(shape)[[3, 2, 3, 2]] # xyxy gain# Match targets to anchorst targets * gain # shape(3,n,7)if nt:# Matchesr t[..., 4:6] / anchors[:, None] # wh ratioj 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# Offsetsgxy t[:, 2:4] # grid xygxi gain[[2, 3]] - gxy # inversej, k ((gxy % 1 g) (gxy 1)).Tl, m ((gxi % 1 g) (gxi 1)).Tj 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# Definebc, gxy, gwh, a t.chunk(4, 1) # (image, class), grid xy, grid wh, anchorsa, (b, c) a.long().view(-1), bc.long().T # anchors, image, classgij (gxy - offsets).long()gi, gj gij.T # grid indices# Appendindices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, gridtbox.append(torch.cat((gxy - gij, gwh), 1)) # boxanch.append(anchors[a]) # anchorstcls.append(c) # class