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
e31d1693
Commit
e31d1693
authored
Aug 20, 2021
by
Vivek Rathod
Committed by
TF Object Detection Team
Aug 20, 2021
Browse files
Support clip_window option with Combined NMS.
PiperOrigin-RevId: 392061572
parent
7c0c0661
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
research/object_detection/core/post_processing.py
research/object_detection/core/post_processing.py
+32
-3
No files found.
research/object_detection/core/post_processing.py
View file @
e31d1693
...
@@ -388,6 +388,28 @@ def _clip_window_prune_boxes(sorted_boxes, clip_window, pad_to_max_output_size,
...
@@ -388,6 +388,28 @@ def _clip_window_prune_boxes(sorted_boxes, clip_window, pad_to_max_output_size,
return
sorted_boxes
,
num_valid_nms_boxes_cumulative
return
sorted_boxes
,
num_valid_nms_boxes_cumulative
def
_clip_boxes
(
boxes
,
clip_window
):
"""Clips boxes to the given window.
Args:
boxes: A [batch, num_boxes, 4] float32 tensor containing box coordinates in
[ymin, xmin, ymax, xmax] form.
clip_window: A [batch, 4] float32 tensor with left top and right bottom
coordinate of the window in [ymin, xmin, ymax, xmax] form.
Returns:
A [batch, num_boxes, 4] float32 tensor containing boxes clipped to the given
window.
"""
ymin
,
xmin
,
ymax
,
xmax
=
tf
.
unstack
(
boxes
,
axis
=-
1
)
clipped_ymin
=
tf
.
maximum
(
ymin
,
clip_window
[:,
0
])
clipped_xmin
=
tf
.
maximum
(
xmin
,
clip_window
[:,
1
])
clipped_ymax
=
tf
.
minimum
(
ymax
,
clip_window
[:,
2
])
clipped_xmax
=
tf
.
minimum
(
xmax
,
clip_window
[:,
3
])
return
tf
.
stack
([
clipped_ymin
,
clipped_xmin
,
clipped_ymax
,
clipped_xmax
],
axis
=-
1
)
class
NullContextmanager
(
object
):
class
NullContextmanager
(
object
):
def
__enter__
(
self
):
def
__enter__
(
self
):
...
@@ -985,10 +1007,10 @@ def batch_multiclass_non_max_suppression(boxes,
...
@@ -985,10 +1007,10 @@ def batch_multiclass_non_max_suppression(boxes,
raise
ValueError
(
'Soft NMS is not supported by combined_nms.'
)
raise
ValueError
(
'Soft NMS is not supported by combined_nms.'
)
if
use_class_agnostic_nms
:
if
use_class_agnostic_nms
:
raise
ValueError
(
'class-agnostic NMS is not supported by combined_nms.'
)
raise
ValueError
(
'class-agnostic NMS is not supported by combined_nms.'
)
if
clip_window
is
not
None
:
if
clip_window
is
None
:
tf
.
logging
.
warning
(
tf
.
logging
.
warning
(
'clip
_
window
is not supported by combined_nms unless it is
'
'
A default
clip
window
of [0. 0. 1. 1.] will be applied for the
'
'
[0. 0. 1. 1.] for each image
.'
)
'
boxes
.'
)
if
additional_fields
is
not
None
:
if
additional_fields
is
not
None
:
tf
.
logging
.
warning
(
'additional_fields is not supported by combined_nms.'
)
tf
.
logging
.
warning
(
'additional_fields is not supported by combined_nms.'
)
if
parallel_iterations
!=
32
:
if
parallel_iterations
!=
32
:
...
@@ -1007,7 +1029,14 @@ def batch_multiclass_non_max_suppression(boxes,
...
@@ -1007,7 +1029,14 @@ def batch_multiclass_non_max_suppression(boxes,
max_total_size
=
max_total_size
,
max_total_size
=
max_total_size
,
iou_threshold
=
iou_thresh
,
iou_threshold
=
iou_thresh
,
score_threshold
=
score_thresh
,
score_threshold
=
score_thresh
,
clip_boxes
=
(
True
if
clip_window
is
None
else
False
),
pad_per_class
=
use_static_shapes
)
pad_per_class
=
use_static_shapes
)
if
clip_window
is
not
None
:
if
clip_window
.
shape
.
ndims
==
1
:
boxes_shape
=
boxes
.
shape
batch_size
=
shape_utils
.
get_dim_as_int
(
boxes_shape
[
0
])
clip_window
=
tf
.
tile
(
clip_window
[
tf
.
newaxis
,
:],
[
batch_size
,
1
])
batch_nmsed_boxes
=
_clip_boxes
(
batch_nmsed_boxes
,
clip_window
)
# Not supported by combined_non_max_suppression.
# Not supported by combined_non_max_suppression.
batch_nmsed_masks
=
None
batch_nmsed_masks
=
None
# Not supported by combined_non_max_suppression.
# Not supported by combined_non_max_suppression.
...
...
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