Commit b88095dc authored by syiming's avatar syiming
Browse files

Add multilevel functions dealing with multilevel features.

parent b3ef7ae9
......@@ -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)
......
......@@ -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):
......
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