"...nn/git@developer.sourcefind.cn:OpenDAS/fairscale.git" did not exist on "30f5009a7d70520dd800d201c43c9dfbece5240f"
Commit c594cecf authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

pr

parent c99e5783
......@@ -217,7 +217,6 @@ class BoxListOpsTest(test_case.TestCase):
def test_iou(self):
def graph_fn():
corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
[0.0, 0.0, 20.0, 20.0]])
......@@ -229,6 +228,31 @@ class BoxListOpsTest(test_case.TestCase):
iou_output = self.execute(graph_fn, [])
self.assertAllClose(iou_output, exp_output)
def test_l1(self):
def graph_fn():
corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
[0.0, 0.0, 20.0, 20.0]])
boxes1 = box_list.BoxList(corners1)
boxes2 = box_list.BoxList(corners2)
l1 = box_list_ops.l1(boxes1, boxes2)
return l1
exp_output = [[5.0, 22.5, 45.5], [8.5, 19.0, 40.0]]
l1_output = self.execute(graph_fn, [])
self.assertAllClose(l1_output, exp_output)
def test_giou(self):
def graph_fn():
corners1 = tf.constant([[5.0, 7.0, 7.0, 9.0]])
corners2 = tf.constant([[5.0, 7.0, 7.0, 9.0], [5.0, 11.0, 7.0, 13.0]])
boxes1 = box_list.BoxList(corners1)
boxes2 = box_list.BoxList(corners2)
giou = box_list_ops.giou_loss(boxes1, boxes2)
return giou
exp_output = [[0.0, 4.0 / 3.0]]
giou_output = self.execute(graph_fn, [])
self.assertAllClose(giou_output, exp_output)
def test_matched_iou(self):
def graph_fn():
corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
......
......@@ -36,7 +36,8 @@ import tensorflow.compat.v1 as tf
from object_detection.core import box_list
from object_detection.core import box_list_ops
from object_detection.utils import ops
from object_detection.box_coders import detr_box_coder
import tensorflow_addons as tfa
class Loss(six.with_metaclass(abc.ABCMeta, object)):
"""Abstract base class for loss functions."""
......@@ -180,7 +181,6 @@ class WeightedSmoothL1LocalizationLoss(Loss):
reduction=tf.losses.Reduction.NONE
), axis=2)
class WeightedIOULocalizationLoss(Loss):
"""IOU localization loss function.
......@@ -203,12 +203,44 @@ class WeightedIOULocalizationLoss(Loss):
loss: a float tensor of shape [batch_size, num_anchors] tensor
representing the value of the loss function.
"""
predicted_boxes = box_list.BoxList(tf.reshape(prediction_tensor, [-1, 4]))
target_boxes = box_list.BoxList(tf.reshape(target_tensor, [-1, 4]))
predicted_boxes = prediction_tensor# box_list.BoxList(tf.reshape(prediction_tensor, [-1, 4]))
target_boxes = target_tensor #box_list.BoxList(tf.reshape(target_tensor, [-1, 4]))
per_anchor_iou_loss = 1.0 - box_list_ops.matched_iou(predicted_boxes,
target_boxes)
print("Weights", weights)
return tf.reshape(weights, [-1]) * per_anchor_iou_loss
class WeightedGIOULocalizationLoss(Loss):
"""IOU localization loss function.
Sums the IOU for corresponding pairs of predicted/groundtruth boxes
and for each pair assign a loss of 1 - IOU. We then compute a weighted
sum over all pairs which is returned as the total loss.
"""
def _compute_loss(self, prediction_tensor, target_tensor, weights):
"""Compute loss function.
Args:
prediction_tensor: A float tensor of shape [batch_size, num_anchors, 4]
representing the decoded predicted boxes
target_tensor: A float tensor of shape [batch_size, num_anchors, 4]
representing the decoded target boxes
weights: a float tensor of shape [batch_size, num_anchors]
Returns:
loss: a float tensor of shape [batch_size, num_anchors] tensor
representing the value of the loss function.
"""
predicted_boxes = prediction_tensor# box_list.BoxList(tf.reshape(prediction_tensor, [-1, 4]))
target_boxes = target_tensor #box_list.BoxList(tf.reshape(target_tensor, [-1, 4]))
#loss_function = tfa.losses.GIouLoss()
per_anchor_iou_loss = tfa.losses.giou_loss(predicted_boxes,target_boxes)
# #1.0 - box_list_ops.matched_iou(predicted_boxes,
# target_boxes)
#print("Weights", weights)
return tf.reshape(weights, [-1]) * per_anchor_iou_loss # * per_anchor_iou_loss
class WeightedSigmoidClassificationLoss(Loss):
"""Sigmoid cross entropy classification loss function."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment