Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
9bd3fe6d
Commit
9bd3fe6d
authored
Jul 24, 2020
by
Kaushik Shivakumar
Browse files
save progress
parent
7359586f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
8 deletions
+48
-8
research/object_detection/core/losses.py
research/object_detection/core/losses.py
+1
-1
research/object_detection/core/region_similarity_calculator.py
...rch/object_detection/core/region_similarity_calculator.py
+33
-7
research/object_detection/core/region_similarity_calculator_test.py
...bject_detection/core/region_similarity_calculator_test.py
+14
-0
No files found.
research/object_detection/core/losses.py
View file @
9bd3fe6d
...
...
@@ -239,7 +239,7 @@ class WeightedGIOULocalizationLoss(Loss):
# #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
return
tf
.
reshape
(
weights
,
[
-
1
])
*
per_anchor_iou_loss
class
WeightedSigmoidClassificationLoss
(
Loss
):
...
...
research/object_detection/core/region_similarity_calculator.py
View file @
9bd3fe6d
...
...
@@ -67,12 +67,17 @@ class IouSimilarity(RegionSimilarityCalculator):
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.
Args:
boxlist1: BoxList holding N 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:
A tensor with shape [N, M] representing pairwise iou scores.
...
...
@@ -80,17 +85,23 @@ class IouSimilarity(RegionSimilarityCalculator):
return
box_list_ops
.
iou
(
boxlist1
,
boxlist2
)
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.
Args:
boxlist1: BoxList holding N 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:
A tensor with shape [N, M] representing pairwise iou scores.
...
...
@@ -108,12 +119,17 @@ class NegSqDistSimilarity(RegionSimilarityCalculator):
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.
Args:
boxlist1: BoxList holding N 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:
A tensor with shape [N, M] representing negated pairwise squared distance.
...
...
@@ -127,12 +143,17 @@ class IoaSimilarity(RegionSimilarityCalculator):
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.
Args:
boxlist1: BoxList holding N 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:
A tensor with shape [N, M] representing pairwise IOA scores.
...
...
@@ -159,12 +180,17 @@ class ThresholdedIouSimilarity(RegionSimilarityCalculator):
super
(
ThresholdedIouSimilarity
,
self
).
__init__
()
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.
Args:
boxlist1: BoxList holding N boxes. Must have a score field.
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:
A tensor with shape [N, M] representing scores threholded by pairwise
...
...
research/object_detection/core/region_similarity_calculator_test.py
View file @
9bd3fe6d
...
...
@@ -93,6 +93,20 @@ class RegionSimilarityCalculatorTest(test_case.TestCase):
iou_output
=
self
.
execute
(
graph_fn
,
[])
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__'
:
tf
.
test
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment