(pred_reg, target_reg, cls_weights, thre, weights)
return iou_loss
compute iou loss
    Args:
        pred_reg ([B,N,7] Tensor): normal boxes: x, y, z, w, l, h, r
        target_reg ([B,N,7] Tensor): anchors
compute iou loss
    Args:
        pred_reg ([B,N,7] Tensor): normal boxes: x, y, z, w, l, h, r
        target_reg ([B,N,7] Tensor): anchors
compute iou loss Args : pred_reg ( [ B N 7 ] Tensor ) : normal boxes : x y z w l h r target_reg ( [ B N 7 ] Tensor ) : anchors
def compute_iou_loss(pred_reg, target_reg, cls_weights, thre, weights):
    """compute iou loss
    Args:
        pred_reg ([B,N,7] Tensor): normal boxes: x, y, z, w, l, h, r
        target_reg ([B,N,7] Tensor): anchors
    """
    cls_weights = torch.max( torch.sigmoid(cls_weights),dim=-1)[0]  ######## select the highest score
    pos = (torch.sigmoid(cls_weights)>thre)
    pos = pos & weights.type_as(pos)

    pos_cls_weights = cls_weights[pos]
    pos_idx = pos.unsqueeze(pos.dim()).expand_as(pred_reg)

    loc_p = pred_reg[pos_idx].view(-1, 7)
    loc_t = target_reg[pos_idx].view(-1, 7)

    if loc_p.shape[0] > 1.0 :
        insect_x = torch.max(torch.min((loc_p[:,0] + loc_p[:,3]/2), (loc_t[:,0] + loc_t[:,3]/2))
                             - torch.max((loc_p[:,0] - loc_p[:,3]/2), (loc_t[:,0] - loc_t[:,3]/2)),
                             pred_reg[:,3].new().resize_(loc_p[:,3].shape).fill_(1e-3))
        insect_y = torch.max(torch.min((loc_p[:,1] + loc_p[:,4]/2), (loc_t[:,1] + loc_t[:,4]/2))
                             - torch.max((loc_p[:,1] - loc_p[:,4]/2), (loc_t[:,1] - loc_t[:,4]/2)),
                             pred_reg[:,4].new().resize_(loc_p[:,4].shape).fill_(1e-3))
        insect_z = torch.max(torch.min((loc_p[:,2] + loc_p[:,5]/2), (loc_t[:,2] + loc_t[:,5]/2))
                             - torch.max((loc_p[:,2] - loc_p[:,5]/2), (loc_t[:,2] - loc_t[:,5]/2)),
                             pred_reg[:,5].new().resize_(loc_p[:,5].shape).fill_(1e-3))

        insect_area = insect_x * insect_y * insect_z
        pred_area = torch.max(loc_p[:, 3] * loc_p[:, 4] * loc_p[:, 5], loc_p.new().resize_(loc_p[:,3].shape).fill_(1e-3))
        tar_area = loc_t[:, 3] * loc_t[:, 4] * loc_t[:, 5]
        iou_tmp = insect_area/(pred_area+tar_area-insect_area)
        iou_tmp =  pos_cls_weights * iou_tmp

        iou_tmp = torch.max(iou_tmp, iou_tmp.new().resize_(iou_tmp.shape).fill_(1e-4))
        iou_loss = -torch.log(iou_tmp)
        iou_loss = iou_loss.mean()
        #print('valid_num:', pos.sum()/pred_reg.shape[0])
        #print('weights:',weights.sum()/pred_reg.shape[0])

    else:
        iou_loss = cls_weights.mean().new().resize_(cls_weights.mean().shape).fill_(0.0)

    return iou_loss
def compute_iou_loss ( pred_reg , target_reg , cls_weights , thre , weights ) : cls_weights = torch . max ( torch . sigmoid ( cls_weights ) , dim = - 1 ) [ 0 ] ######## select the highest score pos = ( torch . sigmoid ( cls_weights ) > thre ) pos = pos & weights . type_as ( pos ) pos_cls_weights = cls_weights [ pos ] pos_idx = pos . unsqueeze ( pos . dim ( ) ) . expand_as ( pred_reg ) loc_p = pred_reg [ pos_idx ] . view ( - 1 , 7 ) loc_t = target_reg [ pos_idx ] . view ( - 1 , 7 ) if loc_p . shape [ 0 ] > 1.0 : insect_x = torch . max ( torch . min ( ( loc_p [ : , 0 ] + loc_p [ : , 3 ] / 2 ) , ( loc_t [ : , 0 ] + loc_t [ : , 3 ] / 2 ) ) - torch . max ( ( loc_p [ : , 0 ] - loc_p [ : , 3 ] / 2 ) , ( loc_t [ : , 0 ] - loc_t [ : , 3 ] / 2 ) ) , pred_reg [ : , 3 ] . new ( ) . resize_ ( loc_p [ : , 3 ] . shape ) . fill_ ( 1e-3 ) ) insect_y = torch . max ( torch . min ( ( loc_p [ : , 1 ] + loc_p [ : , 4 ] / 2 ) , ( loc_t [ : , 1 ] + loc_t [ : , 4 ] / 2 ) ) - torch . max ( ( loc_p [ : , 1 ] - loc_p [ : , 4 ] / 2 ) , ( loc_t [ : , 1 ] - loc_t [ : , 4 ] / 2 ) ) , pred_reg [ : , 4 ] . new ( ) . resize_ ( loc_p [ : , 4 ] . shape ) . fill_ ( 1e-3 ) ) insect_z = torch . max ( torch . min ( ( loc_p [ : , 2 ] + loc_p [ : , 5 ] / 2 ) , ( loc_t [ : , 2 ] + loc_t [ : , 5 ] / 2 ) ) - torch . max ( ( loc_p [ : , 2 ] - loc_p [ : , 5 ] / 2 ) , ( loc_t [ : , 2 ] - loc_t [ : , 5 ] / 2 ) ) , pred_reg [ : , 5 ] . new ( ) . resize_ ( loc_p [ : , 5 ] . shape ) . fill_ ( 1e-3 ) ) insect_area = insect_x * insect_y * insect_z pred_area = torch . max ( loc_p [ : , 3 ] * loc_p [ : , 4 ] * loc_p [ : , 5 ] , loc_p . new ( ) . resize_ ( loc_p [ : , 3 ] . shape ) . fill_ ( 1e-3 ) ) tar_area = loc_t [ : , 3 ] * loc_t [ : , 4 ] * loc_t [ : , 5 ] iou_tmp = insect_area / ( pred_area + tar_area - insect_area ) iou_tmp = pos_cls_weights * iou_tmp iou_tmp = torch . max ( iou_tmp , iou_tmp . new ( ) . resize_ ( iou_tmp . shape ) . fill_ ( 1e-4 ) ) iou_loss = - torch . log ( iou_tmp ) iou_loss = iou_loss . mean ( ) #print('valid_num:', pos.sum()/pred_reg.shape[0]) #print('weights:',weights.sum()/pred_reg.shape[0]) else : iou_loss = cls_weights . mean ( ) . new ( ) . resize_ ( cls_weights . mean ( ) . shape ) . fill_ ( 0.0 ) return iou_loss