Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74a0364

Browse files
authored
Merge pull request tensorflow#2631 from tombstone/feature_extractors_update
feature extractor and model builder update.
2 parents ff88581 + 3237c08 commit 74a0364

23 files changed

+1920
-102
lines changed

research/object_detection/builders/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ py_library(
2424
"//tensorflow_models/object_detection/meta_architectures:faster_rcnn_meta_arch",
2525
"//tensorflow_models/object_detection/meta_architectures:rfcn_meta_arch",
2626
"//tensorflow_models/object_detection/meta_architectures:ssd_meta_arch",
27+
"//tensorflow_models/object_detection/models:embedded_ssd_mobilenet_v1_feature_extractor",
2728
"//tensorflow_models/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor",
29+
"//tensorflow_models/object_detection/models:faster_rcnn_inception_v2_feature_extractor",
2830
"//tensorflow_models/object_detection/models:faster_rcnn_resnet_v1_feature_extractor",
2931
"//tensorflow_models/object_detection/models:ssd_inception_v2_feature_extractor",
32+
"//tensorflow_models/object_detection/models:ssd_inception_v3_feature_extractor",
3033
"//tensorflow_models/object_detection/models:ssd_mobilenet_v1_feature_extractor",
3134
"//tensorflow_models/object_detection/protos:model_py_pb2",
3235
],
@@ -40,7 +43,11 @@ py_test(
4043
"//tensorflow",
4144
"//tensorflow_models/object_detection/meta_architectures:faster_rcnn_meta_arch",
4245
"//tensorflow_models/object_detection/meta_architectures:ssd_meta_arch",
46+
"//tensorflow_models/object_detection/models:faster_rcnn_inception_resnet_v2_feature_extractor",
47+
"//tensorflow_models/object_detection/models:faster_rcnn_inception_v2_feature_extractor",
48+
"//tensorflow_models/object_detection/models:faster_rcnn_resnet_v1_feature_extractor",
4349
"//tensorflow_models/object_detection/models:ssd_inception_v2_feature_extractor",
50+
"//tensorflow_models/object_detection/models:ssd_inception_v3_feature_extractor",
4451
"//tensorflow_models/object_detection/models:ssd_mobilenet_v1_feature_extractor",
4552
"//tensorflow_models/object_detection/protos:model_py_pb2",
4653
],

research/object_detection/builders/model_builder.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,37 @@
2828
from object_detection.meta_architectures import rfcn_meta_arch
2929
from object_detection.meta_architectures import ssd_meta_arch
3030
from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
31+
from object_detection.models import faster_rcnn_inception_v2_feature_extractor as frcnn_inc_v2
32+
from object_detection.models import faster_rcnn_nas_feature_extractor as frcnn_nas
3133
from object_detection.models import faster_rcnn_resnet_v1_feature_extractor as frcnn_resnet_v1
34+
from object_detection.models.embedded_ssd_mobilenet_v1_feature_extractor import EmbeddedSSDMobileNetV1FeatureExtractor
3235
from object_detection.models.ssd_inception_v2_feature_extractor import SSDInceptionV2FeatureExtractor
36+
from object_detection.models.ssd_inception_v3_feature_extractor import SSDInceptionV3FeatureExtractor
3337
from object_detection.models.ssd_mobilenet_v1_feature_extractor import SSDMobileNetV1FeatureExtractor
3438
from object_detection.protos import model_pb2
3539

3640
# A map of names to SSD feature extractors.
3741
SSD_FEATURE_EXTRACTOR_CLASS_MAP = {
3842
'ssd_inception_v2': SSDInceptionV2FeatureExtractor,
43+
'ssd_inception_v3': SSDInceptionV3FeatureExtractor,
3944
'ssd_mobilenet_v1': SSDMobileNetV1FeatureExtractor,
45+
'embedded_ssd_mobilenet_v1': EmbeddedSSDMobileNetV1FeatureExtractor,
4046
}
4147

4248
# A map of names to Faster R-CNN feature extractors.
4349
FASTER_RCNN_FEATURE_EXTRACTOR_CLASS_MAP = {
50+
'faster_rcnn_nas':
51+
frcnn_nas.FasterRCNNNASFeatureExtractor,
52+
'faster_rcnn_inception_resnet_v2':
53+
frcnn_inc_res.FasterRCNNInceptionResnetV2FeatureExtractor,
54+
'faster_rcnn_inception_v2':
55+
frcnn_inc_v2.FasterRCNNInceptionV2FeatureExtractor,
4456
'faster_rcnn_resnet50':
4557
frcnn_resnet_v1.FasterRCNNResnet50FeatureExtractor,
4658
'faster_rcnn_resnet101':
4759
frcnn_resnet_v1.FasterRCNNResnet101FeatureExtractor,
4860
'faster_rcnn_resnet152':
4961
frcnn_resnet_v1.FasterRCNNResnet152FeatureExtractor,
50-
'faster_rcnn_inception_resnet_v2':
51-
frcnn_inc_res.FasterRCNNInceptionResnetV2FeatureExtractor
5262
}
5363

5464

@@ -94,15 +104,18 @@ def _build_ssd_feature_extractor(feature_extractor_config, is_training,
94104
feature_type = feature_extractor_config.type
95105
depth_multiplier = feature_extractor_config.depth_multiplier
96106
min_depth = feature_extractor_config.min_depth
107+
pad_to_multiple = feature_extractor_config.pad_to_multiple
108+
batch_norm_trainable = feature_extractor_config.batch_norm_trainable
97109
conv_hyperparams = hyperparams_builder.build(
98110
feature_extractor_config.conv_hyperparams, is_training)
99111

100112
if feature_type not in SSD_FEATURE_EXTRACTOR_CLASS_MAP:
101113
raise ValueError('Unknown ssd feature_extractor: {}'.format(feature_type))
102114

103115
feature_extractor_class = SSD_FEATURE_EXTRACTOR_CLASS_MAP[feature_type]
104-
return feature_extractor_class(depth_multiplier, min_depth, conv_hyperparams,
105-
reuse_weights)
116+
return feature_extractor_class(is_training, depth_multiplier, min_depth,
117+
pad_to_multiple, conv_hyperparams,
118+
batch_norm_trainable, reuse_weights)
106119

107120

108121
def _build_ssd_model(ssd_config, is_training):
@@ -180,14 +193,16 @@ def _build_faster_rcnn_feature_extractor(
180193
feature_type = feature_extractor_config.type
181194
first_stage_features_stride = (
182195
feature_extractor_config.first_stage_features_stride)
196+
batch_norm_trainable = feature_extractor_config.batch_norm_trainable
183197

184198
if feature_type not in FASTER_RCNN_FEATURE_EXTRACTOR_CLASS_MAP:
185199
raise ValueError('Unknown Faster R-CNN feature_extractor: {}'.format(
186200
feature_type))
187201
feature_extractor_class = FASTER_RCNN_FEATURE_EXTRACTOR_CLASS_MAP[
188202
feature_type]
189203
return feature_extractor_class(
190-
is_training, first_stage_features_stride, reuse_weights)
204+
is_training, first_stage_features_stride,
205+
batch_norm_trainable, reuse_weights)
191206

192207

193208
def _build_faster_rcnn_model(frcnn_config, is_training):
@@ -248,8 +263,13 @@ def _build_faster_rcnn_model(frcnn_config, is_training):
248263
) = post_processing_builder.build(frcnn_config.second_stage_post_processing)
249264
second_stage_localization_loss_weight = (
250265
frcnn_config.second_stage_localization_loss_weight)
266+
second_stage_classification_loss = (
267+
losses_builder.build_faster_rcnn_classification_loss(
268+
frcnn_config.second_stage_classification_loss))
251269
second_stage_classification_loss_weight = (
252270
frcnn_config.second_stage_classification_loss_weight)
271+
second_stage_mask_prediction_loss_weight = (
272+
frcnn_config.second_stage_mask_prediction_loss_weight)
253273

254274
hard_example_miner = None
255275
if frcnn_config.HasField('hard_example_miner'):
@@ -286,6 +306,8 @@ def _build_faster_rcnn_model(frcnn_config, is_training):
286306
'second_stage_score_conversion_fn': second_stage_score_conversion_fn,
287307
'second_stage_localization_loss_weight':
288308
second_stage_localization_loss_weight,
309+
'second_stage_classification_loss':
310+
second_stage_classification_loss,
289311
'second_stage_classification_loss_weight':
290312
second_stage_classification_loss_weight,
291313
'hard_example_miner': hard_example_miner}
@@ -300,4 +322,6 @@ def _build_faster_rcnn_model(frcnn_config, is_training):
300322
maxpool_kernel_size=maxpool_kernel_size,
301323
maxpool_stride=maxpool_stride,
302324
second_stage_mask_rcnn_box_predictor=second_stage_box_predictor,
325+
second_stage_mask_prediction_loss_weight=(
326+
second_stage_mask_prediction_loss_weight),
303327
**common_kwargs)

0 commit comments

Comments
 (0)