Commit 1cf70ed7 authored by syiming's avatar syiming
Browse files

Fix coding style for feature extractor.

parent 7140eede
......@@ -20,9 +20,7 @@ import tensorflow.compat.v1 as tf
from object_detection.meta_architectures import faster_rcnn_meta_arch
from object_detection.models import feature_map_generators
from object_detection.models.keras_models import resnet_v1
from object_detection.models.keras_models import model_utils
from object_detection.utils import ops
from object_detection.utils import shape_utils
_RESNET_MODEL_OUTPUT_LAYERS = {
'resnet_v1_50': ['conv2_block3_out', 'conv3_block4_out',
......@@ -35,7 +33,7 @@ _RESNET_MODEL_OUTPUT_LAYERS = {
class FasterRCNNResnetV1FPNKerasFeatureExtractor(
faster_rcnn_meta_arch.FasterRCNNFeatureExtractor):
faster_rcnn_meta_arch.FasterRCNNKerasFeatureExtractor):
"""Faster RCNN Feature Extractor using Keras-based Resnet V1 FPN features."""
def __init__(self,
......@@ -52,30 +50,24 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
fpn_max_level=7,
additional_layer_depth=256,
override_base_feature_extractor_hyperparams=False):
# FIXME: fix doc string for fpn min level and fpn max level
"""Constructor.
Args:
is_training: See base class.
resnet_v1_base_model: base resnet v1 network to use. One of
the resnet_v1.resnet_v1_{50,101,152} models.
resnet_v1_base_model_name: model name under which to construct resnet v1.
first_stage_features_stride: See base class.
conv_hyperparameters: a `hyperparams_builder.KerasLayerHyperparams` object
containing convolution hyperparameters for the layers added on top of
the base feature extractor.
min_depth: Minimum number of filters in the convolutional layers.
depth_multiplier: The depth multiplier to modify the number of filters
in the convolutional layers.
resnet_v1_base_model: base resnet v1 network to use. One of
the resnet_v1.resnet_v1_{50,101,152} models.
resnet_v1_base_model_name: model name under which to construct resnet v1.
batch_norm_trainable: See base class.
weight_decay: See base class.
fpn_min_level: the highest resolution feature map to use in FPN. The valid
values are {2, 3, 4, 5} which map to MobileNet v1 layers
{Conv2d_3_pointwise, Conv2d_5_pointwise, Conv2d_11_pointwise,
Conv2d_13_pointwise}, respectively.
values are {2, 3, 4, 5} which map to Resnet v1 layers.
fpn_max_level: the smallest resolution feature map to construct or use in
FPN. FPN constructions uses features maps starting from fpn_min_level
upto the fpn_max_level. In the case that there are not enough feature
......@@ -92,22 +84,24 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
"""
if first_stage_features_stride != 8 and first_stage_features_stride != 16:
raise ValueError('`first_stage_features_stride` must be 8 or 16.')
super(FasterRCNNResnetV1FPNKerasFeatureExtractor, self).__init__(
is_training=is_training,
first_stage_features_stride=first_stage_features_stride,
batch_norm_trainable=batch_norm_trainable,
weight_decay=weight_decay)
self._resnet_v1_base_model = resnet_v1_base_model
self._resnet_v1_base_model_name = resnet_v1_base_model_name
self._conv_hyperparams = conv_hyperparams
self._min_depth = min_depth
self._depth_multiplier = depth_multiplier
self._fpn_min_level = fpn_min_level
self._fpn_max_level = fpn_max_level
self._additional_layer_depth = additional_layer_depth
self._freeze_batchnorm = (not batch_norm_trainable)
self._override_base_feature_extractor_hyperparams = \
override_base_feature_extractor_hyperparams
self._fpn_min_level = fpn_min_level
self._fpn_max_level = fpn_max_level
self._resnet_v1_base_model = resnet_v1_base_model
self._resnet_v1_base_model_name = resnet_v1_base_model_name
self._resnet_block_names = ['block1', 'block2', 'block3', 'block4']
self.classification_backbone = None
self._fpn_features_generator = None
......@@ -138,7 +132,7 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
def get_proposal_feature_extractor_model(self, name=None):
"""Returns a model that extracts first stage RPN features.
Extracts features using the first half of the Resnet v1 network.
Extracts features using the Resnet v1 FPN network.
Args:
name: A scope name to construct all variables within.
......@@ -147,6 +141,9 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
A Keras model that takes preprocessed_inputs:
A [batch, height, width, channels] float32 tensor
representing a batch of images.
And returns rpn_feature_map:
A list of tensors with shape [batch, height, width, depth]
"""
with tf.name_scope(name):
with tf.name_scope('ResnetV1FPN'):
......@@ -200,7 +197,7 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
def get_box_classifier_feature_extractor_model(self, name=None):
"""Returns a model that extracts second stage box classifier features.
TODO: doc
Construct two fully connected layer to extract the box classifier features.
Args:
name: A scope name to construct all variables within.
......@@ -210,9 +207,10 @@ class FasterRCNNResnetV1FPNKerasFeatureExtractor(
A 4-D float tensor with shape
[batch_size * self.max_num_proposals, crop_height, crop_width, depth]
representing the feature map cropped to each proposal.
And returns proposal_classifier_features:
A 4-D float tensor with shape
[batch_size * self.max_num_proposals, height, width, depth]
[batch_size * self.max_num_proposals, 1024]
representing box classifier features for each proposal.
"""
with tf.name_scope(name):
......@@ -271,6 +269,7 @@ class FasterRCNNResnet50FPNKerasFeatureExtractor(
additional_layer_depth=additional_layer_depth,
override_base_feature_extractor_hyperparams=override_base_feature_extractor_hyperparams)
class FasterRCNNResnet101FPNKerasFeatureExtractor(
FasterRCNNResnetV1FPNKerasFeatureExtractor):
"""Faster RCNN with Resnet101 FPN feature extractor implementation."""
......
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