yolov8改进-添加Wise-IoU,yolov8损失改进

1.在ultralytics/utils/metrics.py文件里找到 bbox_iou函数

注释整个函数
在这里插入图片描述

2.将注释的函数后面,去添加以下代码(替换上面注释的函数)

class WIoU_Scale:''' monotonous: {None: origin v1True: monotonic FM v2False: non-monotonic FM v3}momentum: The momentum of running mean'''iou_mean = 1.monotonous = False_momentum = 1 - 0.5 ** (1 / 7000)_is_train = Truedef __init__(self, iou):self.iou = iouself._update(self)@classmethoddef _update(cls, self):if cls._is_train: cls.iou_mean = (1 - cls._momentum) * cls.iou_mean + \cls._momentum * self.iou.detach().mean().item()@classmethoddef _scaled_loss(cls, self, gamma=1.9, delta=3):if isinstance(self.monotonous, bool):if self.monotonous:return (self.iou.detach() / self.iou_mean).sqrt()else:beta = self.iou.detach() / self.iou_meanalpha = delta * torch.pow(gamma, beta - delta)return beta / alphareturn 1def bbox_iou(box1, box2, xywh=True, GIoU=False, DIoU=False, CIoU=False, SIoU=False, EIoU=False, WIoU=False, Focal=False,alpha=1, gamma=0.5, scale=False, eps=1e-7):# Returns Intersection over Union (IoU) of box1(1,4) to box2(n,4)# Get the coordinates of bounding boxesif xywh:  # transform from xywh to xyxy(x1, y1, w1, h1), (x2, y2, w2, h2) = box1.chunk(4, -1), box2.chunk(4, -1)w1_, h1_, w2_, h2_ = w1 / 2, h1 / 2, w2 / 2, h2 / 2b1_x1, b1_x2, b1_y1, b1_y2 = x1 - w1_, x1 + w1_, y1 - h1_, y1 + h1_b2_x1, b2_x2, b2_y1, b2_y2 = x2 - w2_, x2 + w2_, y2 - h2_, y2 + h2_else:  # x1, y1, x2, y2 = box1b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, -1)b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, -1)w1, h1 = b1_x2 - b1_x1, (b1_y2 - b1_y1).clamp(eps)w2, h2 = b2_x2 - b2_x1, (b2_y2 - b2_y1).clamp(eps)# Intersection areainter = (b1_x2.minimum(b2_x2) - b1_x1.maximum(b2_x1)).clamp(0) * \(b1_y2.minimum(b2_y2) - b1_y1.maximum(b2_y1)).clamp(0)# Union Areaunion = w1 * h1 + w2 * h2 - inter + epsif scale:self = WIoU_Scale(1 - (inter / union))# IoU# iou = inter / union # ori iouiou = torch.pow(inter / (union + eps), alpha)  # alpha iouif CIoU or DIoU or GIoU or EIoU or SIoU or WIoU:cw = b1_x2.maximum(b2_x2) - b1_x1.minimum(b2_x1)  # convex (smallest enclosing box) widthch = b1_y2.maximum(b2_y2) - b1_y1.minimum(b2_y1)  # convex heightif CIoU or DIoU or EIoU or SIoU or WIoU:  # Distance or Complete IoU https://arxiv.org/abs/1911.08287v1c2 = (cw ** 2 + ch ** 2) ** alpha + eps  # convex diagonal squaredrho2 = (((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4) ** alpha  # center dist ** 2if CIoU:  # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47v = (4 / math.pi ** 2) * (torch.atan(w2 / h2) - torch.atan(w1 / h1)).pow(2)with torch.no_grad():alpha_ciou = v / (v - iou + (1 + eps))if Focal:return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha)), torch.pow(inter / (union + eps),gamma)  # Focal_CIoUelse:return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha))  # CIoUelif EIoU:rho_w2 = ((b2_x2 - b2_x1) - (b1_x2 - b1_x1)) ** 2rho_h2 = ((b2_y2 - b2_y1) - (b1_y2 - b1_y1)) ** 2cw2 = torch.pow(cw ** 2 + eps, alpha)ch2 = torch.pow(ch ** 2 + eps, alpha)if Focal:return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2), torch.pow(inter / (union + eps),gamma)  # Focal_EIouelse:return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2)  # EIouelif SIoU:# SIoU Loss https://arxiv.org/pdf/2205.12740.pdfs_cw = (b2_x1 + b2_x2 - b1_x1 - b1_x2) * 0.5 + epss_ch = (b2_y1 + b2_y2 - b1_y1 - b1_y2) * 0.5 + epssigma = torch.pow(s_cw ** 2 + s_ch ** 2, 0.5)sin_alpha_1 = torch.abs(s_cw) / sigmasin_alpha_2 = torch.abs(s_ch) / sigmathreshold = pow(2, 0.5) / 2sin_alpha = torch.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)angle_cost = torch.cos(torch.arcsin(sin_alpha) * 2 - math.pi / 2)rho_x = (s_cw / cw) ** 2rho_y = (s_ch / ch) ** 2gamma = angle_cost - 2distance_cost = 2 - torch.exp(gamma * rho_x) - torch.exp(gamma * rho_y)omiga_w = torch.abs(w1 - w2) / torch.max(w1, w2)omiga_h = torch.abs(h1 - h2) / torch.max(h1, h2)shape_cost = torch.pow(1 - torch.exp(-1 * omiga_w), 4) + torch.pow(1 - torch.exp(-1 * omiga_h), 4)if Focal:return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha), torch.pow(inter / (union + eps), gamma)  # Focal_SIouelse:return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha)  # SIouelif WIoU:if Focal:raise RuntimeError("WIoU do not support Focal.")elif scale:return getattr(WIoU_Scale, '_scaled_loss')(self), (1 - iou) * torch.exp((rho2 / c2)), iou  # WIoU https://arxiv.org/abs/2301.10051else:return iou, torch.exp((rho2 / c2))  # WIoU v1if Focal:return iou - rho2 / c2, torch.pow(inter / (union + eps), gamma)  # Focal_DIoUelse:return iou - rho2 / c2  # DIoUc_area = cw * ch + eps  # convex areaif Focal:return iou - torch.pow((c_area - union) / c_area + eps, alpha), torch.pow(inter / (union + eps),gamma)  # Focal_GIoU https://arxiv.org/pdf/1902.09630.pdfelse:return iou - torch.pow((c_area - union) / c_area + eps, alpha)  # GIoU https://arxiv.org/pdf/1902.09630.pdfif Focal:return iou, torch.pow(inter / (union + eps), gamma)  # Focal_IoUelse:return iou  # IoU### 源码修改(还原则删除)- loss2 - end

参考链接:

原文链接:https: // blog.csdn.net / darkredrock / article / details / 130292080
原文链接:https: // blog.csdn.net / weixin_45303602 / article / details / 133748724
在这里插入图片描述

3.ultralytics/utils/loss.py文件里,找到BboxLoss类中的forward

找到下面两行代码

iou = bbox_iou(pred_bboxes[fg_mask], target_bboxes[fg_mask], xywh=False, CIoU=True)
loss_iou = ((1.0 - iou) * weight).sum() / target_scores_sum

替换为以下代码:

        # todo 源码修改(还原则删除)- loss6_# # WIoUiou = bbox_iou_for_nms(pred_bboxes[fg_mask], target_bboxes[fg_mask], xywh=False, WIoU=True, scale=True)if type(iou) is tuple:if len(iou) == 2:loss_iou = ((1.0 - iou[0]) * iou[1].detach() * weight).sum() / target_scores_sumelse:loss_iou = (iou[0] * iou[1] * weight).sum() / target_scores_sumelse:loss_iou = ((1.0 - iou) * weight).sum() / target_scores_sum# 源码修改(还原则删除)- loss6 - end

在这里插入图片描述

4.还是loss文件中,添加以下bbox_iou_for_nms代码

# todo 源码修改(还原则删除)- loss7(2)_
def bbox_iou_for_nms(box1, box2, xywh=True, GIoU=False, DIoU=False, CIoU=False, SIoU=False, EIoU=False, WIoU=False,Focal=False, alpha=1, gamma=0.5, scale=False, eps=1e-7):# Returns Intersection over Union (IoU) of box1(1,4) to box2(n,4)# Get the coordinates of bounding boxesif xywh:  # transform from xywh to xyxy(x1, y1, w1, h1), (x2, y2, w2, h2) = box1.chunk(4, -1), box2.chunk(4, -1)w1_, h1_, w2_, h2_ = w1 / 2, h1 / 2, w2 / 2, h2 / 2b1_x1, b1_x2, b1_y1, b1_y2 = x1 - w1_, x1 + w1_, y1 - h1_, y1 + h1_b2_x1, b2_x2, b2_y1, b2_y2 = x2 - w2_, x2 + w2_, y2 - h2_, y2 + h2_else:  # x1, y1, x2, y2 = box1b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, -1)b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, -1)w1, h1 = b1_x2 - b1_x1, (b1_y2 - b1_y1).clamp(eps)w2, h2 = b2_x2 - b2_x1, (b2_y2 - b2_y1).clamp(eps)# Intersection areainter = (b1_x2.minimum(b2_x2) - b1_x1.maximum(b2_x1)).clamp(0) * \(b1_y2.minimum(b2_y2) - b1_y1.maximum(b2_y1)).clamp(0)# Union Areaunion = w1 * h1 + w2 * h2 - inter + epsif scale:self = WIoU_Scale(1 - (inter / union))# IoU# iou = inter / union # ori iouiou = torch.pow(inter / (union + eps), alpha)  # alpha iouif CIoU or DIoU or GIoU or EIoU or SIoU or WIoU:cw = b1_x2.maximum(b2_x2) - b1_x1.minimum(b2_x1)  # convex (smallest enclosing box) widthch = b1_y2.maximum(b2_y2) - b1_y1.minimum(b2_y1)  # convex heightif CIoU or DIoU or EIoU or SIoU or WIoU:  # Distance or Complete IoU https://arxiv.org/abs/1911.08287v1c2 = (cw ** 2 + ch ** 2) ** alpha + eps  # convex diagonal squaredrho2 = (((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4) ** alpha  # center dist ** 2if CIoU:  # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47v = (4 / math.pi ** 2) * (torch.atan(w2 / h2) - torch.atan(w1 / h1)).pow(2)with torch.no_grad():alpha_ciou = v / (v - iou + (1 + eps))if Focal:return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha)), torch.pow(inter / (union + eps),gamma)  # Focal_CIoUelse:return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha))  # CIoUelif EIoU:rho_w2 = ((b2_x2 - b2_x1) - (b1_x2 - b1_x1)) ** 2rho_h2 = ((b2_y2 - b2_y1) - (b1_y2 - b1_y1)) ** 2cw2 = torch.pow(cw ** 2 + eps, alpha)ch2 = torch.pow(ch ** 2 + eps, alpha)if Focal:return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2), torch.pow(inter / (union + eps),gamma)  # Focal_EIouelse:return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2)  # EIouelif SIoU:# SIoU Loss https://arxiv.org/pdf/2205.12740.pdfs_cw = (b2_x1 + b2_x2 - b1_x1 - b1_x2) * 0.5 + epss_ch = (b2_y1 + b2_y2 - b1_y1 - b1_y2) * 0.5 + epssigma = torch.pow(s_cw ** 2 + s_ch ** 2, 0.5)sin_alpha_1 = torch.abs(s_cw) / sigmasin_alpha_2 = torch.abs(s_ch) / sigmathreshold = pow(2, 0.5) / 2sin_alpha = torch.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)angle_cost = torch.cos(torch.arcsin(sin_alpha) * 2 - math.pi / 2)rho_x = (s_cw / cw) ** 2rho_y = (s_ch / ch) ** 2gamma = angle_cost - 2distance_cost = 2 - torch.exp(gamma * rho_x) - torch.exp(gamma * rho_y)omiga_w = torch.abs(w1 - w2) / torch.max(w1, w2)omiga_h = torch.abs(h1 - h2) / torch.max(h1, h2)shape_cost = torch.pow(1 - torch.exp(-1 * omiga_w), 4) + torch.pow(1 - torch.exp(-1 * omiga_h), 4)if Focal:return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha), torch.pow(inter / (union + eps), gamma)  # Focal_SIouelse:return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha)  # SIouelif WIoU:if Focal:raise RuntimeError("WIoU do not support Focal.")elif scale:return getattr(WIoU_Scale, '_scaled_loss')(self), (1 - iou) * torch.exp((rho2 / c2)), iou  # WIoU https://arxiv.org/abs/2301.10051else:return iou, torch.exp((rho2 / c2))  # WIoU v1if Focal:return iou - rho2 / c2, torch.pow(inter / (union + eps), gamma)  # Focal_DIoUelse:return iou - rho2 / c2  # DIoUc_area = cw * ch + eps  # convex areaif Focal:return iou - torch.pow((c_area - union) / c_area + eps, alpha), torch.pow(inter / (union + eps),gamma)  # Focal_GIoU https://arxiv.org/pdf/1902.09630.pdfelse:return iou - torch.pow((c_area - union) / c_area + eps, alpha)  # GIoU https://arxiv.org/pdf/1902.09630.pdfif Focal:return iou, torch.pow(inter / (union + eps), gamma)  # Focal_IoUelse:return iou  # IoU# def soft_nms(bboxes, scores, iou_thresh=0.5, sigma=0.5, score_threshold=0.25):
#     order = torch.arange(0, scores.size(0)).to(bboxes.device)
#     keep = []
#
#     while order.numel() > 1:
#         if order.numel() == 1:
#             keep.append(order[0])
#             break
#         else:
#             i = order[0]
#             keep.append(i)
#         # todo 源码修改(还原则取消注释)- loss10_
#         iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]]).squeeze()
#         # todo 源码修改(还原则删除)- loss11_
#         # iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]],WIoU=True).squeeze()
#         # iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]],WIoU=True)
#
#         idx = (iou > iou_thresh).nonzero().squeeze()
#         if idx.numel() > 0:
#             iou = iou[idx]
#             newScores = torch.exp(-torch.pow(iou, 2) / sigma)
#             scores[order[idx + 1]] *= newScores
#
#         newOrder = (scores[order[1:]] > score_threshold).nonzero().squeeze()
#         if newOrder.numel() == 0:
#             break
#         else:
#             maxScoreIndex = torch.argmax(scores[order[newOrder + 1]])
#             if maxScoreIndex != 0:
#                 newOrder[[0, maxScoreIndex],] = newOrder[[maxScoreIndex, 0],]
#             order = order[newOrder + 1]
#
#     return torch.LongTensor(keep)
# 源码修改(还原则删除)- loss7(2) - end

原参考链接是在metrics.py下添加上述bbox_iou_for_nms代码,可参考,不过我这边报错,已注释

# todo 源码修改(还原则删除)- loss7_
# def bbox_iou_for_nms(box1, box2, xywh=True, GIoU=False, DIoU=False, CIoU=False, SIoU=False, EIoU=False, WIoU=False,
#                      Focal=False, alpha=1, gamma=0.5, scale=False, eps=1e-7):
#     # Returns Intersection over Union (IoU) of box1(1,4) to box2(n,4)
#
#     # Get the coordinates of bounding boxes
#     if xywh:  # transform from xywh to xyxy
#         (x1, y1, w1, h1), (x2, y2, w2, h2) = box1.chunk(4, -1), box2.chunk(4, -1)
#         w1_, h1_, w2_, h2_ = w1 / 2, h1 / 2, w2 / 2, h2 / 2
#         b1_x1, b1_x2, b1_y1, b1_y2 = x1 - w1_, x1 + w1_, y1 - h1_, y1 + h1_
#         b2_x1, b2_x2, b2_y1, b2_y2 = x2 - w2_, x2 + w2_, y2 - h2_, y2 + h2_
#     else:  # x1, y1, x2, y2 = box1
#         b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, -1)
#         b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, -1)
#         w1, h1 = b1_x2 - b1_x1, (b1_y2 - b1_y1).clamp(eps)
#         w2, h2 = b2_x2 - b2_x1, (b2_y2 - b2_y1).clamp(eps)
#
#     # Intersection area
#     inter = (b1_x2.minimum(b2_x2) - b1_x1.maximum(b2_x1)).clamp(0) * \
#             (b1_y2.minimum(b2_y2) - b1_y1.maximum(b2_y1)).clamp(0)
#
#     # Union Area
#     union = w1 * h1 + w2 * h2 - inter + eps
#     if scale:
#         self = WIoU_Scale(1 - (inter / union))
#
#     # IoU
#     # iou = inter / union # ori iou
#     iou = torch.pow(inter / (union + eps), alpha)  # alpha iou
#     if CIoU or DIoU or GIoU or EIoU or SIoU or WIoU:
#         cw = b1_x2.maximum(b2_x2) - b1_x1.minimum(b2_x1)  # convex (smallest enclosing box) width
#         ch = b1_y2.maximum(b2_y2) - b1_y1.minimum(b2_y1)  # convex height
#         if CIoU or DIoU or EIoU or SIoU or WIoU:  # Distance or Complete IoU https://arxiv.org/abs/1911.08287v1
#             c2 = (cw ** 2 + ch ** 2) ** alpha + eps  # convex diagonal squared
#             rho2 = (((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (
#                         b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4) ** alpha  # center dist ** 2
#             if CIoU:  # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47
#                 v = (4 / math.pi ** 2) * (torch.atan(w2 / h2) - torch.atan(w1 / h1)).pow(2)
#                 with torch.no_grad():
#                     alpha_ciou = v / (v - iou + (1 + eps))
#                 if Focal:
#                     return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha)), torch.pow(inter / (union + eps),
#                                                                                                  gamma)  # Focal_CIoU
#                 else:
#                     return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha))  # CIoU
#             elif EIoU:
#                 rho_w2 = ((b2_x2 - b2_x1) - (b1_x2 - b1_x1)) ** 2
#                 rho_h2 = ((b2_y2 - b2_y1) - (b1_y2 - b1_y1)) ** 2
#                 cw2 = torch.pow(cw ** 2 + eps, alpha)
#                 ch2 = torch.pow(ch ** 2 + eps, alpha)
#                 if Focal:
#                     return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2), torch.pow(inter / (union + eps),
#                                                                                       gamma)  # Focal_EIou
#                 else:
#                     return iou - (rho2 / c2 + rho_w2 / cw2 + rho_h2 / ch2)  # EIou
#             elif SIoU:
#                 # SIoU Loss https://arxiv.org/pdf/2205.12740.pdf
#                 s_cw = (b2_x1 + b2_x2 - b1_x1 - b1_x2) * 0.5 + eps
#                 s_ch = (b2_y1 + b2_y2 - b1_y1 - b1_y2) * 0.5 + eps
#                 sigma = torch.pow(s_cw ** 2 + s_ch ** 2, 0.5)
#                 sin_alpha_1 = torch.abs(s_cw) / sigma
#                 sin_alpha_2 = torch.abs(s_ch) / sigma
#                 threshold = pow(2, 0.5) / 2
#                 sin_alpha = torch.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)
#                 angle_cost = torch.cos(torch.arcsin(sin_alpha) * 2 - math.pi / 2)
#                 rho_x = (s_cw / cw) ** 2
#                 rho_y = (s_ch / ch) ** 2
#                 gamma = angle_cost - 2
#                 distance_cost = 2 - torch.exp(gamma * rho_x) - torch.exp(gamma * rho_y)
#                 omiga_w = torch.abs(w1 - w2) / torch.max(w1, w2)
#                 omiga_h = torch.abs(h1 - h2) / torch.max(h1, h2)
#                 shape_cost = torch.pow(1 - torch.exp(-1 * omiga_w), 4) + torch.pow(1 - torch.exp(-1 * omiga_h), 4)
#                 if Focal:
#                     return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha), torch.pow(
#                         inter / (union + eps), gamma)  # Focal_SIou
#                 else:
#                     return iou - torch.pow(0.5 * (distance_cost + shape_cost) + eps, alpha)  # SIou
#             elif WIoU:
#                 if Focal:
#                     raise RuntimeError("WIoU do not support Focal.")
#                 elif scale:
#                     return getattr(WIoU_Scale, '_scaled_loss')(self), (1 - iou) * torch.exp(
#                         (rho2 / c2)), iou  # WIoU https://arxiv.org/abs/2301.10051
#                 else:
#                     return iou, torch.exp((rho2 / c2))  # WIoU v1
#             if Focal:
#                 return iou - rho2 / c2, torch.pow(inter / (union + eps), gamma)  # Focal_DIoU
#             else:
#                 return iou - rho2 / c2  # DIoU
#         c_area = cw * ch + eps  # convex area
#         if Focal:
#             return iou - torch.pow((c_area - union) / c_area + eps, alpha), torch.pow(inter / (union + eps),
#                                                                                       gamma)  # Focal_GIoU https://arxiv.org/pdf/1902.09630.pdf
#         else:
#             return iou - torch.pow((c_area - union) / c_area + eps, alpha)  # GIoU https://arxiv.org/pdf/1902.09630.pdf
#     if Focal:
#         return iou, torch.pow(inter / (union + eps), gamma)  # Focal_IoU
#     else:
#         return iou  # IoU
#
#
# def soft_nms(bboxes, scores, iou_thresh=0.5, sigma=0.5, score_threshold=0.25):
#     order = torch.arange(0, scores.size(0)).to(bboxes.device)
#     keep = []
#
#     while order.numel() > 1:
#         if order.numel() == 1:
#             keep.append(order[0])
#             break
#         else:
#             i = order[0]
#             keep.append(i)
#         # todo 源码修改(还原则取消注释)- loss10_
#         # iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]]).squeeze()
#         # todo 源码修改(还原则删除)- loss11_
#         # iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]],WIoU=True).squeeze()
#         """
#         # 如果,iou等于下面这个-1
#         iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]],WIoU=True)
#         print(f"--------为解决bug,打印iou--------:{iou}")
#         print(f"--------为解决bug,打印iou的类型--------:{type(iou)}") #<class 'tuple'>
#         print(f"--------为解决bug,打印iou[0]的形状--------:{iou[0].shape}") # torch.Size([503, 1]) # torch.Size([6693, 1]) # torch.Size([4298, 1])
#         print(f"--------为解决bug,打印iou[1]的形状--------:{iou[1].shape}") # torch.Size([503, 1]) # torch.Size([6693, 1]) # torch.Size([4298, 1])
#         print(f"--------为解决bug,打印iou的len--------:{len(iou)}") # 2
#         # 那么,iou是元组类型,元组里装了两个tensor,每个tensor的shape [x,1] # 即 (tensor(x,1),tensor(x,1))
#         """
#         """
#         # 如果,iou等于下面这个-2
#         iou = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]],WIoU=True)[0]
#         print(f"--------为解决bug,打印iou--------:{iou}")
#         print(f"--------为解决bug,打印iou的类型--------:{type(iou)}") # <class 'torch.Tensor'>
#         print(f"--------为解决bug,打印iou[0]的形状--------:{iou[0].shape}") # torch.Size([1])
#         print(f"--------为解决bug,打印iou[1]的形状--------:{iou[1].shape}") # torch.Size([1])
#         print(f"--------为解决bug,打印iou的len--------:{len(iou)}") # 29
#         # scores[order[idx + 1]] *= newScores --报错--> # RuntimeError:  The size of tensor a (16) must match the size of tensor b (2) at non-singleton dimension 1
#         """
#
#         """
#         # 如果,iou等于下面这个-3
#         iou_temp = bbox_iou_for_nms(bboxes[i], bboxes[order[1:]], WIoU=True)
#         iou = (iou_temp[0].squeeze(),iou_temp[1].squeeze())
#         print(f"--------为解决bug,打印iou--------:{iou}")
#         print(f"--------为解决bug,打印iou的类型--------:{type(iou)}")
#         print(f"--------为解决bug,打印iou[0]的形状--------:{iou[0].shape}")
#         print(f"--------为解决bug,打印iou[1]的形状--------:{iou[1].shape}")
#         print(f"--------为解决bug,打印iou的len--------:{len(iou)}")
#         """
#         pass
#         idx = (iou > iou_thresh).nonzero().squeeze()
#         if idx.numel() > 0:
#             iou = iou[idx]
#             newScores = torch.exp(-torch.pow(iou, 2) / sigma)
#             scores[order[idx + 1]] *= newScores
#
#         newOrder = (scores[order[1:]] > score_threshold).nonzero().squeeze()
#         if newOrder.numel() == 0:
#             break
#         else:
#             maxScoreIndex = torch.argmax(scores[order[newOrder + 1]])
#             if maxScoreIndex != 0:
#                 newOrder[[0, maxScoreIndex],] = newOrder[[maxScoreIndex, 0],]
#             order = order[newOrder + 1]
#
#     return torch.LongTensor(keep)
# 源码修改(还原则删除)- loss7 - end

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/238176.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【K8s】2# 使用kuboard管理K8s集群(kuboard安装)

文章目录 安装 Kuboard v3部署计划 安装登录测试 安装 Kuboard v3 部署计划 在正式安装 kuboard v3 之前&#xff0c;需做好一个简单的部署计划的设计&#xff0c;在本例中&#xff0c;各组件之间的连接方式&#xff0c;如下图所示&#xff1a; 假设用户通过 http://外网IP:80…

油猴脚本教程案例【键盘监听】-编写 ChatGPT 快捷键优化

文章目录 1. 元数据1. name2. namespace3. version4. description5. author6. match7. grant8. icon 2. 编写函数.1 函数功能2.1.1. input - 聚焦发言框2.1.2. stop - 取消回答2.1.3. newFunction - 开启新窗口2.1.4. scroll - 回到底部 3. 监听键盘事件3.1 监听X - 开启新对话…

飞天使-k8s知识点4-验证安装好后功能

文章目录 接k8s知识点2之验证集群功能创建dashboard验证安装nginx 并访问tomcat 访问 接k8s知识点2之验证集群功能 [rootkubeadm-master2 tmp]# kubectl run net-test1 --imagealpine sleep 36000 pod/net-test1 created [rootkubeadm-master2 tmp]# kubectl get pod NAME …

转义字符使用详解【C语言】

目录 转义字符的概念 转义字符表 转义字符详解 和 实际使用示例 一、\a 二、\b 三、\f 四、\n 五、\r 六、\t 七、\v 八、\\ 九、\ 十、\" 十一、\? 十二、\0 十三、\ddd 十四、\xhh 总结—— 转义字符的概念 所有的 ASCII码都可以用“\加数字” 来表示…

华为Harmony——ArkTs语言

文章目录 一、简单示例二、声明式UI描述创建组件无参有参数 配置属性配置事件配置子组件 三、自定义组件基本用法基本结构成员函数/变量 一、简单示例 我们以一个具体的示例来说明ArkTS的基本组成。如下图所示&#xff0c;当开发者点击按钮时&#xff0c;文本内容从“Hello Wo…

博客引擎 hugo intro 入门介绍+安装笔记

hugo 博客引擎 Hugo 是一个流行的静态网站生成器&#xff0c;它被广泛用于创建博客和静态网站。 静态网站生成器&#xff1a;Hugo 是一个静态网站生成器&#xff0c;它将你的博客内容转换为 HTML、CSS 和 JavaScript 文件&#xff0c;这些文件可以直接部署到 Web 服务器上。相…

【C语言】动态内存管理基础知识——动态通讯录,如何实现通讯录容量的动态化

引言 动态内存管理的函数有&#xff1a;malloc,calloc,ralloc,free,本文讲解动态内存函数和使用&#xff0c;如何进行动态内存管理,实现通讯录联系人容量的动态化&#xff0c;对常见动态内存错误进行总结。 ✨ 猪巴戒&#xff1a;个人主页✨ 所属专栏&#xff1a;《C语言进阶》…

老毛桃软碟通制作启动盘装机硬盘安装系统

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《产品经理如何画泳道图&流程图》 ⛺️ 越努力 &#xff0c;越幸运 目录 一、老毛桃制作winPE镜像 1、简介 2、老毛桃的主要功能包括&#xff1a; 3、准备 4、制作启动盘流程 5…

vue项目npm run build报错npm ERR! missing script: build(已解决)

vue项目npm run build报错npm ERR! missing script: build&#xff08;已解决&#xff09; 错误描述&#xff1a; 今天准备打包vue项目上线是出现下列错误&#xff1a; 找了很多解决方法都不行&#xff0c;最后打开自己的package.json文件发现&#xff1a;build后面多了个&a…

内皮素-1(Endothelin-1 )ELISA kit

灵敏、快速的内皮素-1 ELISA试剂盒&#xff0c;适用于心血管和应激相关研究 内皮素&#xff08;Endothelin, ET&#xff09;是由血管内皮细胞产生的异肽&#xff0c;具有强大的血管收缩活性。这种肽由三个独立的基因编码&#xff0c;经过加工产生39个残基的 大ET 分子&#xff…

【科普知识】什么是步进驱动器、驱动模式及驱动的方法?

我们已经知道步进电机就是一种将电脉冲信号转化为角位移的执行机构。那么如何精准地控制电机的速度和位置呢&#xff1f;这就需要一种驱动器的装置。 1.什么是步进驱动器&#xff1f; 电机控制原理图 步进驱动器是一种能使步进电机运转的功率放大器&#xff0c;能把控制器发来…

Zabbix自动发现并注册已安装agent的主机

先在被监控主机上安装好zabbix-agent 然后登录zabbix网页 点击发现动作后会出现第三步 然后编辑操作&#xff0c;发现后加入到主机组群 然后编辑发现规则 然后就可以在主机列表中看到被发现的主机。

window下搭建Rocketmq服务及测试demo

下载地址&#xff1a;下载 | RocketMQ 一. RocketMQ部署 系统:Windows7;环境:JDK1.8、Maven3.3、Git&#xff1b; 下载 | RocketMQ 1.1 下载&#xff0c; 进入RocketMQ官网http://rocketmq.apache.org/docs/quick-start/&#xff0c; 这里以编写时的最新版本为例&#…

大疆又出新品:户外电源

大疆创新最近发布了两款强大的户外电源&#xff1a;DJI Power 1000 和 DJI Power 500。这两款产品都具有高效储能、便携易用、安全放心、续航强大等优势&#xff0c;让你在户外探险时拥有更多可能性。 DJI Power 1000 电池容量&#xff1a;1024 瓦时&#xff08;约 1 度电&…

光条中心线提取-Steger算法 [OpenCV]

在线结构光视觉传感器中&#xff0c;由线激光器发射出的线结构光&#xff0c;在本质上为一个连续且具有一定厚度的空间光平面&#xff0c;而在目标表面上所形成的具有一定宽度的光条特征&#xff0c;即为该光平面与目标表面相交而成的交线。在该空间光平面的厚度方向上&#xf…

0x43 线段树

0x43 线段树 线段树&#xff08;Segment Tree&#xff09;是一种基于分治思想的二叉树结构&#xff0c;用于在区间进行信息统计。与按照二进制位&#xff08;2的次幂&#xff09;进行区间划分的树状数组相比&#xff0c;线段树是一种更加通用的结构&#xff1a; 1.线段树的每…

Hadoop 集群环境搭建

目录 第一部分&#xff1a;系统安装... 3 1&#xff1a;图形化安装... 3 2&#xff1a;选择中文... 3 3&#xff1a;安装选项... 3 4&#xff1a;软件选项... 4 5&#xff1a;安装位置... 4 6&#xff1a;网络配置... 6 7&#xff1a;开始安装... 7 8&#xff1a;创建用户... 7…

TypeScript实战——ChatGPT前端自适应手机端,PC端

前言 「作者主页」&#xff1a;雪碧有白泡泡 「个人网站」&#xff1a;雪碧的个人网站 可以在线体验哦&#xff1a;体验地址 文章目录 前言引言先看效果PC端手机端 实现原理解释 包的架构目录 引言 ChatGPT是由OpenAI开发的一种基于语言模型的对话系统。它是GPT&#xff08;…

esp32-s3训练自己的数据进行目标检测、图像分类

esp32-s3训练自己的数据进行目标检测、图像分类 一、下载项目二、环境三、训练和导出模型四、部署模型五、存在的问题 esp-idf的安装参考我前面的文章&#xff1a; esp32cam和esp32-s3烧录human_face_detect实现人脸识别 一、下载项目 训练、转换模型&#xff1a;ModelAssist…

外汇天眼:我碰到外汇投资骗局了吗?学会这5招,轻松识别外汇诈骗黑平台!

近年来外汇市场因为交易量大、流动性大、不容易被控盘、品种简单、风险相对低等特色&#xff0c;因此吸引不少投资人青睐&#xff0c;成为全球金融市场的热门选择。 然而&#xff0c;市面上充斥许多诈骗集团设立的黑平台&#xff0c;也打着投资外汇的名义行骗&#xff0c;不免会…