在OD API中使用IoU本地化丢失

时间:2019-03-27 12:25:21

标签: tensorflow object-detection-api

几篇论文,例如this one,声称IoU本地化损失比标准平滑L1损失具有更好的性能。

当尝试使用IoU本地化丢失时,即在配置文件中使用以下行:

...
localization_loss {
   weighted_iou {
   }
}
...

我总是会收到found NaN in loss错误。如果我在1e-7的分母中添加一个小常数(例如matched_iou),就像这样:

def matched_iou(boxlist1, boxlist2, scope=None):
  """Compute intersection-over-union between corresponding boxes in boxlists.

  Args:
    boxlist1: BoxList holding N boxes
    boxlist2: BoxList holding N boxes
    scope: name scope.

  Returns:
    a tensor with shape [N] representing pairwise iou scores.
  """
  with tf.name_scope(scope, 'MatchedIOU'):
    intersections = matched_intersection(boxlist1, boxlist2)
    areas1 = area(boxlist1)
    areas2 = area(boxlist2)
    unions = areas1 + areas2 - intersections
    eps = 1e-7  # <- this is the small constant
    return tf.where(
        tf.equal(intersections, 0.0),
        tf.zeros_like(intersections), tf.truediv(intersections, unions + eps))

NaN错误消失了,但是损耗值确实很高,并且训练没有收敛。

对于这种现象的任何提示,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

经过一点点代码挖掘,似乎prediction_tensortarget_tensor作为编码张量(相对于锚框)进入了IOU损失函数。 因此,IoU函数在无意义的值上运行,导致它期望它以解码格式。.根据您使用的编码器,有一个在BoxCoder下对其进行解码的函数,但问题是使用您需要anchor boxes ..并将锚定框放入损失函数中并不是那么容易。