Skip to content

Commit 3ca571d

Browse files
aquariusjayYknZhu
authored andcommittedMay 19, 2018
PiperOrigin-RevId: 197225788
1 parent 9dec261 commit 3ca571d

20 files changed

+1454
-98
lines changed
 

‎research/deeplab/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,27 @@ Misc:
104104

105105
To get help with issues you may encounter while using the DeepLab Tensorflow
106106
implementation, create a new question on
107-
[StackOverflow](https://stackoverflow.com/) with the tags "tensorflow" and
108-
"deeplab".
107+
[StackOverflow](https://stackoverflow.com/) with the tag "tensorflow".
109108

110109
Please report bugs (i.e., broken code, not usage questions) to the
111110
tensorflow/models GitHub [issue
112111
tracker](https://github.com/tensorflow/models/issues), prefixing the issue name
113112
with "deeplab".
114113

114+
## Change Logs
115+
116+
### March 22, 2018
117+
118+
Release checkpoints using MobileNet-V2 as network backbone and pretrained on
119+
PASCAL VOC 2012 and Cityscapes.
120+
121+
122+
### March 5, 2018
123+
124+
First release of DeepLab in TensorFlow including deeper Xception network
125+
backbone. Include chekcpoints that have been pretrained on PASCAL VOC 2012
126+
and Cityscapes.
127+
115128
## References
116129

117130
1. **Semantic Image Segmentation with Deep Convolutional Nets and Fully Connected CRFs**<br />

‎research/deeplab/common.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
# Test set name.
9696
TEST_SET = 'test'
9797

98+
9899
class ModelOptions(
99100
collections.namedtuple('ModelOptions', [
100101
'outputs_to_num_classes',
@@ -109,7 +110,8 @@ class ModelOptions(
109110
'decoder_output_stride',
110111
'decoder_use_separable_conv',
111112
'logits_kernel_size',
112-
'model_variant'
113+
'model_variant',
114+
'depth_multiplier',
113115
])):
114116
"""Immutable class to hold model options."""
115117

@@ -139,4 +141,4 @@ def __new__(cls,
139141
FLAGS.aspp_with_batch_norm, FLAGS.aspp_with_separable_conv,
140142
FLAGS.multi_grid, FLAGS.decoder_output_stride,
141143
FLAGS.decoder_use_separable_conv, FLAGS.logits_kernel_size,
142-
FLAGS.model_variant)
144+
FLAGS.model_variant, FLAGS.depth_multiplier)

‎research/deeplab/core/feature_extractor.py

+80-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import functools
1818
import tensorflow as tf
1919

20+
from deeplab.core import resnet_v1_beta
2021
from deeplab.core import xception
21-
from nets.mobilenet import mobilenet as mobilenet_lib
22+
from tensorflow.contrib.slim.nets import resnet_utils
2223
from nets.mobilenet import mobilenet_v2
2324

2425

@@ -56,10 +57,12 @@ def _mobilenet_v2(net,
5657
"""
5758
with tf.variable_scope(
5859
scope, 'MobilenetV2', [net], reuse=reuse) as scope:
59-
return mobilenet_lib.mobilenet_base(
60+
return mobilenet_v2.mobilenet_base(
6061
net,
6162
conv_defs=mobilenet_v2.V2_DEF,
62-
multiplier=depth_multiplier,
63+
depth_multiplier=depth_multiplier,
64+
min_depth=8 if depth_multiplier == 1.0 else 1,
65+
divisible_by=8 if depth_multiplier == 1.0 else 1,
6366
final_endpoint=final_endpoint or _MOBILENET_V2_FINAL_ENDPOINT,
6467
output_stride=output_stride,
6568
scope=scope)
@@ -68,13 +71,25 @@ def _mobilenet_v2(net,
6871
# A map from network name to network function.
6972
networks_map = {
7073
'mobilenet_v2': _mobilenet_v2,
74+
'resnet_v1_50': resnet_v1_beta.resnet_v1_50,
75+
'resnet_v1_50_beta': resnet_v1_beta.resnet_v1_50_beta,
76+
'resnet_v1_101': resnet_v1_beta.resnet_v1_101,
77+
'resnet_v1_101_beta': resnet_v1_beta.resnet_v1_101_beta,
78+
'xception_41': xception.xception_41,
7179
'xception_65': xception.xception_65,
80+
'xception_71': xception.xception_71,
7281
}
7382

7483
# A map from network name to network arg scope.
7584
arg_scopes_map = {
7685
'mobilenet_v2': mobilenet_v2.training_scope,
86+
'resnet_v1_50': resnet_utils.resnet_arg_scope,
87+
'resnet_v1_50_beta': resnet_utils.resnet_arg_scope,
88+
'resnet_v1_101': resnet_utils.resnet_arg_scope,
89+
'resnet_v1_101_beta': resnet_utils.resnet_arg_scope,
90+
'xception_41': xception.xception_arg_scope,
7791
'xception_65': xception.xception_arg_scope,
92+
'xception_71': xception.xception_arg_scope,
7893
}
7994

8095
# Names for end point features.
@@ -86,19 +101,49 @@ def _mobilenet_v2(net,
86101
# The provided checkpoint does not include decoder module.
87102
DECODER_END_POINTS: None,
88103
},
104+
'resnet_v1_50': {
105+
DECODER_END_POINTS: ['block1/unit_2/bottleneck_v1/conv3'],
106+
},
107+
'resnet_v1_50_beta': {
108+
DECODER_END_POINTS: ['block1/unit_2/bottleneck_v1/conv3'],
109+
},
110+
'resnet_v1_101': {
111+
DECODER_END_POINTS: ['block1/unit_2/bottleneck_v1/conv3'],
112+
},
113+
'resnet_v1_101_beta': {
114+
DECODER_END_POINTS: ['block1/unit_2/bottleneck_v1/conv3'],
115+
},
116+
'xception_41': {
117+
DECODER_END_POINTS: [
118+
'entry_flow/block2/unit_1/xception_module/'
119+
'separable_conv2_pointwise',
120+
],
121+
},
89122
'xception_65': {
90123
DECODER_END_POINTS: [
91124
'entry_flow/block2/unit_1/xception_module/'
92125
'separable_conv2_pointwise',
93126
],
94-
}
127+
},
128+
'xception_71': {
129+
DECODER_END_POINTS: [
130+
'entry_flow/block2/unit_1/xception_module/'
131+
'separable_conv2_pointwise',
132+
],
133+
},
95134
}
96135

97136
# A map from feature extractor name to the network name scope used in the
98137
# ImageNet pretrained versions of these models.
99138
name_scope = {
100139
'mobilenet_v2': 'MobilenetV2',
140+
'resnet_v1_50': 'resnet_v1_50',
141+
'resnet_v1_50_beta': 'resnet_v1_50',
142+
'resnet_v1_101': 'resnet_v1_101',
143+
'resnet_v1_101_beta': 'resnet_v1_101',
144+
'xception_41': 'xception_41',
101145
'xception_65': 'xception_65',
146+
'xception_71': 'xception_71',
102147
}
103148

104149
# Mean pixel value.
@@ -118,7 +163,13 @@ def _preprocess_zero_mean_unit_range(inputs):
118163

119164
_PREPROCESS_FN = {
120165
'mobilenet_v2': _preprocess_zero_mean_unit_range,
166+
'resnet_v1_50': _preprocess_subtract_imagenet_mean,
167+
'resnet_v1_50_beta': _preprocess_zero_mean_unit_range,
168+
'resnet_v1_101': _preprocess_subtract_imagenet_mean,
169+
'resnet_v1_101_beta': _preprocess_zero_mean_unit_range,
170+
'xception_41': _preprocess_zero_mean_unit_range,
121171
'xception_65': _preprocess_zero_mean_unit_range,
172+
'xception_71': _preprocess_zero_mean_unit_range,
122173
}
123174

124175

@@ -140,7 +191,8 @@ def mean_pixel(model_variant=None):
140191
Returns:
141192
Mean pixel value.
142193
"""
143-
if model_variant is None:
194+
if model_variant in ['resnet_v1_50',
195+
'resnet_v1_101'] or model_variant is None:
144196
return _MEAN_RGB
145197
else:
146198
return [127.5, 127.5, 127.5]
@@ -159,7 +211,8 @@ def extract_features(images,
159211
regularize_depthwise=False,
160212
preprocess_images=True,
161213
num_classes=None,
162-
global_pool=False):
214+
global_pool=False,
215+
use_bounded_activations=False):
163216
"""Extracts features by the particular model_variant.
164217
165218
Args:
@@ -184,6 +237,8 @@ def extract_features(images,
184237
to None for dense prediction tasks.
185238
global_pool: Global pooling for image classification task. Defaults to
186239
False, since dense prediction tasks do not use this.
240+
use_bounded_activations: Whether or not to use bounded activations. Bounded
241+
activations better lend themselves to quantized inference.
187242
188243
Returns:
189244
features: A tensor of size [batch, feature_height, feature_width,
@@ -195,7 +250,25 @@ def extract_features(images,
195250
Raises:
196251
ValueError: Unrecognized model variant.
197252
"""
198-
if 'xception' in model_variant:
253+
if 'resnet' in model_variant:
254+
arg_scope = arg_scopes_map[model_variant](
255+
weight_decay=weight_decay,
256+
batch_norm_decay=0.95,
257+
batch_norm_epsilon=1e-5,
258+
batch_norm_scale=True,
259+
activation_fn=tf.nn.relu6 if use_bounded_activations else tf.nn.relu)
260+
features, end_points = get_network(
261+
model_variant, preprocess_images, arg_scope)(
262+
inputs=images,
263+
num_classes=num_classes,
264+
is_training=(is_training and fine_tune_batch_norm),
265+
global_pool=global_pool,
266+
output_stride=output_stride,
267+
multi_grid=multi_grid,
268+
reuse=reuse,
269+
scope=name_scope[model_variant],
270+
use_bounded_activations=use_bounded_activations)
271+
elif 'xception' in model_variant:
199272
arg_scope = arg_scopes_map[model_variant](
200273
weight_decay=weight_decay,
201274
batch_norm_decay=0.9997,

0 commit comments

Comments
 (0)