? 小白剛開始學(xué)習(xí)YOLOv5,跟隨老哥的步驟走了一遍目標(biāo)檢測--手把手教你搭建自己的YOLOv5目標(biāo)檢測平臺
? 最后訓(xùn)練最后一步出現(xiàn)RuntimeError: result type Float can‘t be cast to the desired output type __int64報(bào)錯(cuò)文章來源:http://www.zghlxwxcb.cn/news/detail-503687.html
解決方法:找到5.0版報(bào)錯(cuò)的loss.py中最后那段for函數(shù),將其整體替換為yolov5-master版中l(wèi)oss.py最后一段for函數(shù)即可正常運(yùn)行文章來源地址http://www.zghlxwxcb.cn/news/detail-503687.html
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
到了這里,關(guān)于RuntimeError: result type Float can‘t be cast to the desired output type __int64報(bào)錯(cuò)解決方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!