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
170c71cc
Commit
170c71cc
authored
Jul 02, 2021
by
Ronny Votel
Committed by
TF Object Detection Team
Jul 02, 2021
Browse files
Minor change to mask target assigner to optionally scale boxes before assigning dense loss weights.
PiperOrigin-RevId: 382773317
parent
13100073
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
research/object_detection/core/target_assigner.py
research/object_detection/core/target_assigner.py
+14
-2
research/object_detection/meta_architectures/center_net_meta_arch.py
...ject_detection/meta_architectures/center_net_meta_arch.py
+1
-1
research/object_detection/utils/target_assigner_utils.py
research/object_detection/utils/target_assigner_utils.py
+12
-1
No files found.
research/object_detection/core/target_assigner.py
View file @
170c71cc
...
...
@@ -2003,8 +2003,20 @@ def _resize_masks(masks, height, width, method):
class
CenterNetMaskTargetAssigner
(
object
):
"""Wrapper to compute targets for segmentation masks."""
def
__init__
(
self
,
stride
):
def
__init__
(
self
,
stride
,
boxes_scale
=
1.0
):
"""Constructor.
Args:
stride: The stride of the network. Targets are assigned at the output
stride.
boxes_scale: Scale to apply to boxes before producing mask weights. This
is meant to ensure the full object region is properly weighted prior to
applying loss. A value of ~1.05 is typically applied when object regions
should be blacked out (perhaps because valid groundtruth masks are not
present).
"""
self
.
_stride
=
stride
self
.
_boxes_scale
=
boxes_scale
def
assign_segmentation_targets
(
self
,
gt_masks_list
,
gt_classes_list
,
gt_boxes_list
=
None
,
...
...
@@ -2072,7 +2084,7 @@ class CenterNetMaskTargetAssigner(object):
segmentation_weight_for_image
=
(
ta_utils
.
blackout_pixel_weights_by_box_regions
(
output_height
,
output_width
,
boxes_absolute
.
get
(),
blackout
,
weights
=
gt_mask_weights
))
weights
=
gt_mask_weights
,
boxes_scale
=
self
.
_boxes_scale
))
segmentation_weights_list
.
append
(
segmentation_weight_for_image
)
else
:
segmentation_weights_list
.
append
(
tf
.
ones
((
output_height
,
output_width
),
...
...
research/object_detection/meta_architectures/center_net_meta_arch.py
View file @
170c71cc
...
...
@@ -2655,7 +2655,7 @@ class CenterNetMetaArch(model.DetectionModel):
per_keypoint_depth
=
kp_params
.
per_keypoint_depth
))
if
self
.
_mask_params
is
not
None
:
target_assigners
[
SEGMENTATION_TASK
]
=
(
cn_assigner
.
CenterNetMaskTargetAssigner
(
stride
))
cn_assigner
.
CenterNetMaskTargetAssigner
(
stride
,
boxes_scale
=
1.05
))
if
self
.
_densepose_params
is
not
None
:
dp_stride
=
1
if
self
.
_densepose_params
.
upsample_to_input_res
else
stride
target_assigners
[
DENSEPOSE_TASK
]
=
(
...
...
research/object_detection/utils/target_assigner_utils.py
View file @
170c71cc
...
...
@@ -16,6 +16,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
shape_utils
...
...
@@ -290,7 +292,8 @@ def get_valid_keypoint_mask_for_class(keypoint_coordinates,
def
blackout_pixel_weights_by_box_regions
(
height
,
width
,
boxes
,
blackout
,
weights
=
None
):
weights
=
None
,
boxes_scale
=
1.0
):
"""Apply weights at pixel locations.
This function is used to generate the pixel weight mask (usually in the output
...
...
@@ -332,6 +335,10 @@ def blackout_pixel_weights_by_box_regions(height, width, boxes, blackout,
a value to apply in each box region. Note that if blackout=True for a
given box, the weight will be zero. If None, all weights are assumed to be
1.
boxes_scale: The amount to scale the height/width of the boxes before
constructing the blackout regions. This is often useful to guarantee that
the proper weight fully covers the object boxes/masks during supervision,
as shifting might occur during image resizing, network stride, etc.
Returns:
A float tensor with shape [height, width] where all values within the
...
...
@@ -347,6 +354,10 @@ def blackout_pixel_weights_by_box_regions(height, width, boxes, blackout,
(
y_grid
,
x_grid
)
=
image_shape_to_grids
(
height
,
width
)
y_grid
=
tf
.
expand_dims
(
y_grid
,
axis
=
0
)
x_grid
=
tf
.
expand_dims
(
x_grid
,
axis
=
0
)
boxlist
=
box_list
.
BoxList
(
boxes
)
boxlist
=
box_list_ops
.
scale_height_width
(
boxlist
,
y_scale
=
boxes_scale
,
x_scale
=
boxes_scale
)
boxes
=
boxlist
.
get
()
y_min
=
tf
.
expand_dims
(
boxes
[:,
0
:
1
],
axis
=-
1
)
x_min
=
tf
.
expand_dims
(
boxes
[:,
1
:
2
],
axis
=-
1
)
y_max
=
tf
.
expand_dims
(
boxes
[:,
2
:
3
],
axis
=-
1
)
...
...
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