From 2bf720c380b268bcf19d2a2c0535780087599bff Mon Sep 17 00:00:00 2001 From: JiaQi Xu <47347516+bubbliiiing@users.noreply.github.com> Date: Tue, 26 May 2020 19:29:02 +0800 Subject: [PATCH] Update ious.py --- nets/ious.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/nets/ious.py b/nets/ious.py index b5bd994..1f7fc39 100644 --- a/nets/ious.py +++ b/nets/ious.py @@ -1,7 +1,6 @@ from keras import backend as K import tensorflow as tf import math - def box_ciou(b1, b2): """ 输入为: @@ -34,7 +33,7 @@ def box_ciou(b1, b2): b1_area = b1_wh[..., 0] * b1_wh[..., 1] b2_area = b2_wh[..., 0] * b2_wh[..., 1] union_area = b1_area + b2_area - intersect_area - iou = intersect_area / (union_area + K.epsilon()) + iou = intersect_area / K.maximum(union_area,K.epsilon()) # 计算中心的差距 center_distance = K.sum(K.square(b1_xy - b2_xy), axis=-1) @@ -44,11 +43,11 @@ def box_ciou(b1, b2): enclose_wh = K.maximum(enclose_maxes - enclose_mins, 0.0) # 计算对角线距离 enclose_diagonal = K.sum(K.square(enclose_wh), axis=-1) - ciou = iou - 1.0 * (center_distance) / (enclose_diagonal + K.epsilon()) + ciou = iou - 1.0 * (center_distance) / K.maximum(enclose_diagonal ,K.epsilon()) - v = 4*K.square(tf.math.atan2(b1_wh[..., 0], b1_wh[..., 1]) - tf.math.atan2(b2_wh[..., 0], b2_wh[..., 1])) / (math.pi * math.pi) - alpha = v / (1.0 - iou + v) + v = 4*K.square(tf.math.atan2(b1_wh[..., 0], K.maximum(b1_wh[..., 1],K.epsilon())) - tf.math.atan2(b2_wh[..., 0], K.maximum(b2_wh[..., 1],K.epsilon()))) / (math.pi * math.pi) + alpha = v / K.maximum((1.0 - iou + v), K.epsilon()) ciou = ciou - alpha * v ciou = K.expand_dims(ciou, -1) - return ciou \ No newline at end of file + return ciou -- GitLab