Commit 90106a40 authored by syiming's avatar syiming
Browse files

Modify code to suit multiscale anchor generator

parent 86fe1753
...@@ -451,11 +451,6 @@ class FasterRCNNMetaArch(model.DetectionModel): ...@@ -451,11 +451,6 @@ class FasterRCNNMetaArch(model.DetectionModel):
# in the future. # in the future.
super(FasterRCNNMetaArch, self).__init__(num_classes=num_classes) super(FasterRCNNMetaArch, self).__init__(num_classes=num_classes)
if not isinstance(first_stage_anchor_generator,
grid_anchor_generator.GridAnchorGenerator):
raise ValueError('first_stage_anchor_generator must be of type '
'grid_anchor_generator.GridAnchorGenerator.')
self._is_training = is_training self._is_training = is_training
self._image_resizer_fn = image_resizer_fn self._image_resizer_fn = image_resizer_fn
self._resize_masks = resize_masks self._resize_masks = resize_masks
...@@ -492,9 +487,7 @@ class FasterRCNNMetaArch(model.DetectionModel): ...@@ -492,9 +487,7 @@ class FasterRCNNMetaArch(model.DetectionModel):
hyperparams_builder.KerasLayerHyperparams): hyperparams_builder.KerasLayerHyperparams):
num_anchors_per_location = ( num_anchors_per_location = (
self._first_stage_anchor_generator.num_anchors_per_location()) self._first_stage_anchor_generator.num_anchors_per_location())
if len(num_anchors_per_location) != 1:
raise ValueError('anchor_generator is expected to generate anchors '
'corresponding to a single feature map.')
conv_hyperparams = ( conv_hyperparams = (
first_stage_box_predictor_arg_scope_fn) first_stage_box_predictor_arg_scope_fn)
self._first_stage_box_predictor_first_conv = ( self._first_stage_box_predictor_first_conv = (
...@@ -1321,18 +1314,16 @@ class FasterRCNNMetaArch(model.DetectionModel): ...@@ -1321,18 +1314,16 @@ class FasterRCNNMetaArch(model.DetectionModel):
if not isinstance(rpn_features_to_crop, list): if not isinstance(rpn_features_to_crop, list):
rpn_features_to_crop = [rpn_features_to_crop] rpn_features_to_crop = [rpn_features_to_crop]
feature_map_shapes = []
rpn_box_predictor_features = [] rpn_box_predictor_features = []
anchors = []
for single_rpn_features_to_crop in rpn_features_to_crop: for single_rpn_features_to_crop in rpn_features_to_crop:
feature_map_shape = tf.shape(single_rpn_features_to_crop) single_shape = tf.shape(single_rpn_features_to_crop)
level_anchors = box_list_ops.concatenate( feature_map_shapes.append((single_shape[1], single_shape[2]))
self._first_stage_anchor_generator.generate([(feature_map_shape[1],
feature_map_shape[2])]))
anchors.append(level_anchors)
single_rpn_box_predictor_features = ( single_rpn_box_predictor_features = (
self._first_stage_box_predictor_first_conv(single_rpn_features_to_crop)) self._first_stage_box_predictor_first_conv(single_rpn_features_to_crop))
rpn_box_predictor_features.append(single_rpn_box_predictor_features) rpn_box_predictor_features.append(single_rpn_box_predictor_features)
anchors = box_list_ops.concatenate(anchors) anchors = box_list_ops.concatenate(
self._first_stage_anchor_generator.generate(feature_map_shapes))
return (rpn_box_predictor_features, rpn_features_to_crop, return (rpn_box_predictor_features, rpn_features_to_crop,
anchors, image_shape) anchors, image_shape)
...@@ -1379,9 +1370,9 @@ class FasterRCNNMetaArch(model.DetectionModel): ...@@ -1379,9 +1370,9 @@ class FasterRCNNMetaArch(model.DetectionModel):
""" """
num_anchors_per_location = ( num_anchors_per_location = (
self._first_stage_anchor_generator.num_anchors_per_location()) self._first_stage_anchor_generator.num_anchors_per_location())
if len(num_anchors_per_location) != 1: # if len(num_anchors_per_location) != 1:
raise RuntimeError('anchor_generator is expected to generate anchors ' # raise RuntimeError('anchor_generator is expected to generate anchors '
'corresponding to a single feature map.') # 'corresponding to a single feature map.')
if self._first_stage_box_predictor.is_keras_model: if self._first_stage_box_predictor.is_keras_model:
box_predictions = self._first_stage_box_predictor( box_predictions = self._first_stage_box_predictor(
rpn_box_predictor_features) rpn_box_predictor_features)
......
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