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
b88095dc
Commit
b88095dc
authored
Jun 23, 2020
by
syiming
Browse files
Add multilevel functions dealing with multilevel features.
parent
b3ef7ae9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
research/object_detection/meta_architectures/faster_rcnn_meta_arch.py
...ect_detection/meta_architectures/faster_rcnn_meta_arch.py
+8
-2
research/object_detection/utils/spatial_transform_ops.py
research/object_detection/utils/spatial_transform_ops.py
+27
-0
No files found.
research/object_detection/meta_architectures/faster_rcnn_meta_arch.py
View file @
b88095dc
...
...
@@ -1963,7 +1963,7 @@ class FasterRCNNMetaArch(model.DetectionModel):
second stage box classifier for each proposal.
Args:
features_to_crop: A float32 tensor with shape
features_to_crop: A
list of
float32 tensor with shape
[batch_size, height, width, depth]
proposal_boxes_normalized: A float32 tensor with shape [batch_size,
num_proposals, box_code_size] containing proposal boxes in
...
...
@@ -1973,9 +1973,15 @@ class FasterRCNNMetaArch(model.DetectionModel):
Returns:
A float32 tensor with shape [K, new_height, new_width, depth].
"""
num_levels
=
len
(
features_to_crop
)
box_levels
=
None
if
num_levels
!=
1
:
# If there are mutiple levels to select, get the box levels
box_levels
=
ops
.
fpn_feature_levels
(
num_levels
,
num_levels
-
1
,
1.0
/
224
,
proposal_boxes_normalized
)
cropped_regions
=
self
.
_flatten_first_two_dimensions
(
self
.
_crop_and_resize_fn
(
features_to_crop
,
proposal_boxes_normalized
,
features_to_crop
,
proposal_boxes_normalized
,
box_levels
,
[
self
.
_initial_crop_size
,
self
.
_initial_crop_size
]))
return
self
.
_maxpool_layer
(
cropped_regions
)
...
...
research/object_detection/utils/spatial_transform_ops.py
View file @
b88095dc
...
...
@@ -411,6 +411,19 @@ def multilevel_roi_align(features, boxes, box_levels, output_size,
return
features_per_box
def
multilevel_native_crop_and_resize
(
images
,
boxes
,
box_levels
,
crop_size
,
scope
=
None
):
#FIXME: fix docstring
"""doc string."""
if
not
box_levels
:
return
native_crop_and_resize
(
images
[
0
],
boxes
,
crop_size
,
scope
=
None
)
croped_feature_list
=
[]
for
level
,
image
in
enumerate
(
images
):
level_boxes
=
tf
.
gather
(
boxes
,
box_levels
==
(
level
-
1
))
cropped
=
native_crop_and_resize
(
image
,
level_boxes
,
crop_size
)
croped_feature_list
.
append
(
cropped
)
return
tf
.
concat
(
croped_feature_list
,
axis
=
0
)
def
native_crop_and_resize
(
image
,
boxes
,
crop_size
,
scope
=
None
):
"""Same as `matmul_crop_and_resize` but uses tf.image.crop_and_resize."""
def
get_box_inds
(
proposals
):
...
...
@@ -430,6 +443,20 @@ def native_crop_and_resize(image, boxes, crop_size, scope=None):
tf
.
shape
(
cropped_regions
)[
1
:]],
axis
=
0
)
return
tf
.
reshape
(
cropped_regions
,
final_shape
)
def
multilevel_matmul_crop_and_resize
(
images
,
boxes
,
box_levels
,
crop_size
,
extrapolation_value
=
0.0
,
scope
=
None
):
#FIXME: fix docstring
"""doc string."""
with
tf
.
name_scope
(
scope
,
'MatMulCropAndResize'
):
if
box_levels
is
None
:
box_levels
=
tf
.
zeros
(
tf
.
shape
(
boxes
)[:
2
],
dtype
=
tf
.
int32
)
return
multilevel_roi_align
([
image
],
boxes
,
box_levels
,
crop_size
,
align_corners
=
True
,
extrapolation_value
=
extrapolation_value
)
def
matmul_crop_and_resize
(
image
,
boxes
,
crop_size
,
extrapolation_value
=
0.0
,
scope
=
None
):
...
...
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