Commit 9bd3fe6d authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

save progress

parent 7359586f
...@@ -239,7 +239,7 @@ class WeightedGIOULocalizationLoss(Loss): ...@@ -239,7 +239,7 @@ class WeightedGIOULocalizationLoss(Loss):
# #1.0 - box_list_ops.matched_iou(predicted_boxes, # #1.0 - box_list_ops.matched_iou(predicted_boxes,
# target_boxes) # target_boxes)
#print("Weights", weights) #print("Weights", weights)
return tf.reshape(weights, [-1]) * per_anchor_iou_loss # * per_anchor_iou_loss return tf.reshape(weights, [-1]) * per_anchor_iou_loss
class WeightedSigmoidClassificationLoss(Loss): class WeightedSigmoidClassificationLoss(Loss):
......
...@@ -67,12 +67,17 @@ class IouSimilarity(RegionSimilarityCalculator): ...@@ -67,12 +67,17 @@ class IouSimilarity(RegionSimilarityCalculator):
This class computes pairwise similarity between two BoxLists based on IOU. This class computes pairwise similarity between two BoxLists based on IOU.
""" """
def _compare(self, boxlist1, boxlist2): def _compare(self, boxlist1, boxlist2,
groundtruth_labels=None, predicted_labels=None):
"""Compute pairwise IOU similarity between the two BoxLists. """Compute pairwise IOU similarity between the two BoxLists.
Args: Args:
boxlist1: BoxList holding N boxes. boxlist1: BoxList holding N boxes.
boxlist2: BoxList holding M boxes. boxlist2: BoxList holding M boxes.
groundtruth_labels: a Tensor of shape [num_boxes, num_classes]
containing groundtruth labels.
predicted_labels: a Tensor of shape [num_boxes, num_classes]
containing predicted labels.
Returns: Returns:
A tensor with shape [N, M] representing pairwise iou scores. A tensor with shape [N, M] representing pairwise iou scores.
...@@ -80,17 +85,23 @@ class IouSimilarity(RegionSimilarityCalculator): ...@@ -80,17 +85,23 @@ class IouSimilarity(RegionSimilarityCalculator):
return box_list_ops.iou(boxlist1, boxlist2) return box_list_ops.iou(boxlist1, boxlist2)
class DETRSimiliarity(RegionSimilarityCalculator): class DETRSimiliarity(RegionSimilarityCalculator):
"""Class to compute similarity based on Intersection over Union (IOU) metric. """Class to compute similarity for the Detection Transformer model.
This class computes pairwise similarity between two BoxLists based on IOU. This class computes pairwise similarity between two BoxLists using a weighted
combination of IOU, classification scores, and the L1 loss.
""" """
def _compare(self, boxlist1, boxlist2, groundtruth_labels=None, predicted_labels=None): def _compare(self, boxlist1, boxlist2,
groundtruth_labels=None, predicted_labels=None):
"""Compute pairwise IOU similarity between the two BoxLists. """Compute pairwise IOU similarity between the two BoxLists.
Args: Args:
boxlist1: BoxList holding N boxes. boxlist1: BoxList holding N boxes.
boxlist2: BoxList holding M boxes. boxlist2: BoxList holding M boxes.
groundtruth_labels: a Tensor of shape [num_boxes, num_classes]
containing groundtruth labels.
predicted_labels: a Tensor of shape [num_boxes, num_classes]
containing predicted labels.
Returns: Returns:
A tensor with shape [N, M] representing pairwise iou scores. A tensor with shape [N, M] representing pairwise iou scores.
...@@ -108,12 +119,17 @@ class NegSqDistSimilarity(RegionSimilarityCalculator): ...@@ -108,12 +119,17 @@ class NegSqDistSimilarity(RegionSimilarityCalculator):
negative squared distance metric. negative squared distance metric.
""" """
def _compare(self, boxlist1, boxlist2, groundtruth_labels=None, predicted_labels=None): def _compare(self, boxlist1, boxlist2,
groundtruth_labels=None, predicted_labels=None):
"""Compute matrix of (negated) sq distances. """Compute matrix of (negated) sq distances.
Args: Args:
boxlist1: BoxList holding N boxes. boxlist1: BoxList holding N boxes.
boxlist2: BoxList holding M boxes. boxlist2: BoxList holding M boxes.
groundtruth_labels: a Tensor of shape [num_boxes, num_classes]
containing groundtruth labels.
predicted_labels: a Tensor of shape [num_boxes, num_classes]
containing predicted labels.
Returns: Returns:
A tensor with shape [N, M] representing negated pairwise squared distance. A tensor with shape [N, M] representing negated pairwise squared distance.
...@@ -127,12 +143,17 @@ class IoaSimilarity(RegionSimilarityCalculator): ...@@ -127,12 +143,17 @@ class IoaSimilarity(RegionSimilarityCalculator):
pairwise intersections divided by the areas of second BoxLists. pairwise intersections divided by the areas of second BoxLists.
""" """
def _compare(self, boxlist1, boxlist2, groundtruth_labels=None, predicted_labels=None): def _compare(self, boxlist1, boxlist2,
groundtruth_labels=None, predicted_labels=None):
"""Compute pairwise IOA similarity between the two BoxLists. """Compute pairwise IOA similarity between the two BoxLists.
Args: Args:
boxlist1: BoxList holding N boxes. boxlist1: BoxList holding N boxes.
boxlist2: BoxList holding M boxes. boxlist2: BoxList holding M boxes.
groundtruth_labels: a Tensor of shape [num_boxes, num_classes]
containing groundtruth labels.
predicted_labels: a Tensor of shape [num_boxes, num_classes]
containing predicted labels.
Returns: Returns:
A tensor with shape [N, M] representing pairwise IOA scores. A tensor with shape [N, M] representing pairwise IOA scores.
...@@ -159,12 +180,17 @@ class ThresholdedIouSimilarity(RegionSimilarityCalculator): ...@@ -159,12 +180,17 @@ class ThresholdedIouSimilarity(RegionSimilarityCalculator):
super(ThresholdedIouSimilarity, self).__init__() super(ThresholdedIouSimilarity, self).__init__()
self._iou_threshold = iou_threshold self._iou_threshold = iou_threshold
def _compare(self, boxlist1, boxlist2, groundtruth_labels=None, predicted_labels=None): def _compare(self, boxlist1, boxlist2,
groundtruth_labels=None, predicted_labels=None):
"""Compute pairwise IOU similarity between the two BoxLists and score. """Compute pairwise IOU similarity between the two BoxLists and score.
Args: Args:
boxlist1: BoxList holding N boxes. Must have a score field. boxlist1: BoxList holding N boxes. Must have a score field.
boxlist2: BoxList holding M boxes. boxlist2: BoxList holding M boxes.
groundtruth_labels: a Tensor of shape [num_boxes, num_classes]
containing groundtruth labels.
predicted_labels: a Tensor of shape [num_boxes, num_classes]
containing predicted labels.
Returns: Returns:
A tensor with shape [N, M] representing scores threholded by pairwise A tensor with shape [N, M] representing scores threholded by pairwise
......
...@@ -93,6 +93,20 @@ class RegionSimilarityCalculatorTest(test_case.TestCase): ...@@ -93,6 +93,20 @@ class RegionSimilarityCalculatorTest(test_case.TestCase):
iou_output = self.execute(graph_fn, []) iou_output = self.execute(graph_fn, [])
self.assertAllClose(iou_output, exp_output) self.assertAllClose(iou_output, exp_output)
def test_detr_similarity(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]])
groundtruth_labels = tf.constant([[]])
boxes1 = box_list.BoxList(corners1)
boxes2 = box_list.BoxList(corners2)
iou_similarity_calculator = region_similarity_calculator.IouSimilarity()
iou_similarity = iou_similarity_calculator.compare(boxes1, boxes2)
return iou_similarity
exp_output = [[2.0 / 16.0, 0, 6.0 / 400.0], [1.0 / 16.0, 0.0, 5.0 / 400.0]]
iou_output = self.execute(graph_fn, [])
self.assertAllClose(iou_output, exp_output)
if __name__ == '__main__': if __name__ == '__main__':
tf.test.main() tf.test.main()
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