"git@developer.sourcefind.cn:Fzc7075/nunchaku.git" did not exist on "af6b1a3c4a00bb0f2b5328242ea0832df7ca1b48"
Commit b968a6ce authored by Mark Sandler's avatar Mark Sandler Committed by Jonathan Huang
Browse files

Merged commit includes the following changes: (#7800)

280142968  by Zhichao Lu:

    Opensource MobilenetEdgeTPU + ssdlite into third-party object detection APIs on EdgeTPU.

--
280134001  by Zhichao Lu:

    Adds MobilenetEdgeTpu + ssdlite into internal object detection APIs on EdgeTPU.

--
278941778  by Zhichao Lu:

    Add support for fixed input shapes for 'encoded_image_string_tensor' and 'tf_example' inputs.

--
278933274  by Zhichao Lu:

      Adding fool proof check to avoid using 1x1 depthwise conv op.

--
278762192  by Zhichao Lu:

    Ensure correct number of iterations after training resumes.

--
278746440  by Zhichao Lu:

    Internal change.

--
278006953  by Zhichao Lu:

    Internal changes to tf.contrib symbols

--
278006330  by Zhichao Lu:

    Internal changes to tf.contrib symbols

--
277593959  by Zhichao Lu:

      Make the ssd_feature_extractor_test.py PY3 compatible. The "six.zip" will use "itertools.izip" in Python 2 and "zip" in Python 3.

--
277344551  by Zhichao Lu:

    Internal change.

--
277154953  by Zhichao Lu:

    Conditionally use keras based optimizers so that check-pointing works correctly.
    This change also enables summaries on TPU which were previously not enabled
    due to a bug.

--
277087572  by Zhichao Lu:

    Fix resizing boxes when using keep_aspect_ratio_rezier with padding.

--
275898543  by Zhichao Lu:

    Support label_map_proto as input in label_map_util.

--
275347137  by Zhichao Lu:

    Add force_no_resize flag in eval.proto which replaces
    the resize config with identity resizer. This is useful
    when we want to test at the original image resolution.

--

PiperOrigin-RevId: 280142968
parent c3bd5082
......@@ -16,6 +16,7 @@
"""SSDFeatureExtractor for MobilenetV1 PPN features."""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -24,7 +25,7 @@ from object_detection.utils import ops
from object_detection.utils import shape_utils
from nets import mobilenet_v1
slim = tf.contrib.slim
slim = contrib_slim
class SSDMobileNetV1PpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
......
......@@ -16,11 +16,12 @@
"""Tests for ssd_mobilenet_v1_ppn_feature_extractor."""
import numpy as np
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_feature_extractor_test
from object_detection.models import ssd_mobilenet_v1_ppn_feature_extractor
slim = tf.contrib.slim
slim = contrib_slim
class SsdMobilenetV1PpnFeatureExtractorTest(
......
......@@ -16,6 +16,7 @@
"""SSDFeatureExtractor for MobilenetV2 features."""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -25,7 +26,7 @@ from object_detection.utils import shape_utils
from nets.mobilenet import mobilenet
from nets.mobilenet import mobilenet_v2
slim = tf.contrib.slim
slim = contrib_slim
class SSDMobileNetV2FeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
......
......@@ -18,12 +18,13 @@ from absl.testing import parameterized
import numpy as np
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_feature_extractor_test
from object_detection.models import ssd_mobilenet_v2_feature_extractor
from object_detection.models import ssd_mobilenet_v2_keras_feature_extractor
slim = tf.contrib.slim
slim = contrib_slim
@parameterized.parameters(
......
......@@ -18,6 +18,7 @@
import copy
import functools
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -27,7 +28,7 @@ from object_detection.utils import shape_utils
from nets.mobilenet import mobilenet
from nets.mobilenet import mobilenet_v2
slim = tf.contrib.slim
slim = contrib_slim
# A modified config of mobilenet v2 that makes it more detection friendly.
......
......@@ -21,12 +21,13 @@ Keras-based Mobilenet V2 FPN feature extractors in SSD.
from absl.testing import parameterized
import numpy as np
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_feature_extractor_test
from object_detection.models import ssd_mobilenet_v2_fpn_feature_extractor
from object_detection.models import ssd_mobilenet_v2_fpn_keras_feature_extractor
slim = tf.contrib.slim
slim = contrib_slim
@parameterized.parameters(
......
......@@ -15,6 +15,7 @@
"""SSDFeatureExtractor for MobileNetV3 features."""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -24,10 +25,10 @@ from object_detection.utils import shape_utils
from nets.mobilenet import mobilenet
from nets.mobilenet import mobilenet_v3
slim = tf.contrib.slim
slim = contrib_slim
class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
class SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
"""Base class of SSD feature extractor using MobilenetV3 features."""
def __init__(self,
......@@ -41,7 +42,8 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
reuse_weights=None,
use_explicit_padding=False,
use_depthwise=False,
override_base_feature_extractor_hyperparams=False):
override_base_feature_extractor_hyperparams=False,
scope_name='MobilenetV3'):
"""MobileNetV3 Feature Extractor for SSD Models.
MobileNet v3. Details found in:
......@@ -66,8 +68,9 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
override_base_feature_extractor_hyperparams: Whether to override
hyperparameters of the base feature extractor with the one from
`conv_hyperparams_fn`.
scope_name: scope name (string) of network variables.
"""
super(_SSDMobileNetV3FeatureExtractorBase, self).__init__(
super(SSDMobileNetV3FeatureExtractorBase, self).__init__(
is_training=is_training,
depth_multiplier=depth_multiplier,
min_depth=min_depth,
......@@ -80,6 +83,7 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
)
self._conv_defs = conv_defs
self._from_layer = from_layer
self._scope_name = scope_name
def preprocess(self, resized_inputs):
"""SSD preprocessing.
......@@ -129,7 +133,8 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
'use_explicit_padding': self._use_explicit_padding,
}
with tf.variable_scope('MobilenetV3', reuse=self._reuse_weights) as scope:
with tf.variable_scope(
self._scope_name, reuse=self._reuse_weights) as scope:
with slim.arg_scope(
mobilenet_v3.training_scope(is_training=None, bn_decay=0.9997)), \
slim.arg_scope(
......@@ -137,7 +142,6 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
with (slim.arg_scope(self._conv_hyperparams_fn())
if self._override_base_feature_extractor_hyperparams else
context_manager.IdentityContextManager()):
# TODO(bochen): switch to v3 modules once v3 is properly refactored.
_, image_features = mobilenet_v3.mobilenet_base(
ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
conv_defs=self._conv_defs,
......@@ -156,7 +160,7 @@ class _SSDMobileNetV3FeatureExtractorBase(ssd_meta_arch.SSDFeatureExtractor):
return feature_maps.values()
class SSDMobileNetV3LargeFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
class SSDMobileNetV3LargeFeatureExtractor(SSDMobileNetV3FeatureExtractorBase):
"""Mobilenet V3-Large feature extractor."""
def __init__(self,
......@@ -168,7 +172,8 @@ class SSDMobileNetV3LargeFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
reuse_weights=None,
use_explicit_padding=False,
use_depthwise=False,
override_base_feature_extractor_hyperparams=False):
override_base_feature_extractor_hyperparams=False,
scope_name='MobilenetV3'):
super(SSDMobileNetV3LargeFeatureExtractor, self).__init__(
conv_defs=mobilenet_v3.V3_LARGE_DETECTION,
from_layer=['layer_14/expansion_output', 'layer_17'],
......@@ -180,11 +185,12 @@ class SSDMobileNetV3LargeFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
reuse_weights=reuse_weights,
use_explicit_padding=use_explicit_padding,
use_depthwise=use_depthwise,
override_base_feature_extractor_hyperparams=override_base_feature_extractor_hyperparams
override_base_feature_extractor_hyperparams=override_base_feature_extractor_hyperparams,
scope_name=scope_name
)
class SSDMobileNetV3SmallFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
class SSDMobileNetV3SmallFeatureExtractor(SSDMobileNetV3FeatureExtractorBase):
"""Mobilenet V3-Small feature extractor."""
def __init__(self,
......@@ -196,7 +202,8 @@ class SSDMobileNetV3SmallFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
reuse_weights=None,
use_explicit_padding=False,
use_depthwise=False,
override_base_feature_extractor_hyperparams=False):
override_base_feature_extractor_hyperparams=False,
scope_name='MobilenetV3'):
super(SSDMobileNetV3SmallFeatureExtractor, self).__init__(
conv_defs=mobilenet_v3.V3_SMALL_DETECTION,
from_layer=['layer_10/expansion_output', 'layer_13'],
......@@ -208,5 +215,6 @@ class SSDMobileNetV3SmallFeatureExtractor(_SSDMobileNetV3FeatureExtractorBase):
reuse_weights=reuse_weights,
use_explicit_padding=use_explicit_padding,
use_depthwise=use_depthwise,
override_base_feature_extractor_hyperparams=override_base_feature_extractor_hyperparams
override_base_feature_extractor_hyperparams=override_base_feature_extractor_hyperparams,
scope_name=scope_name
)
......@@ -15,12 +15,13 @@
"""Tests for ssd_mobilenet_v3_feature_extractor."""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_mobilenet_v3_feature_extractor
from object_detection.models import ssd_mobilenet_v3_feature_extractor_testbase
slim = tf.contrib.slim
slim = contrib_slim
class SsdMobilenetV3LargeFeatureExtractorTest(
......
......@@ -18,11 +18,12 @@ import abc
import numpy as np
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_feature_extractor_test
slim = tf.contrib.slim
slim = contrib_slim
class _SsdMobilenetV3FeatureExtractorTestBase(
......
......@@ -19,6 +19,7 @@ Based on PNASNet ImageNet model: https://arxiv.org/abs/1712.00559
"""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -27,7 +28,7 @@ from object_detection.utils import ops
from object_detection.utils import variables_helper
from nets.nasnet import pnasnet
slim = tf.contrib.slim
slim = contrib_slim
def pnasnet_large_arg_scope_for_detection(is_batch_norm_training=False):
......
......@@ -16,11 +16,12 @@
"""Tests for ssd_pnas_feature_extractor."""
import numpy as np
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.models import ssd_feature_extractor_test
from object_detection.models import ssd_pnasnet_feature_extractor
slim = tf.contrib.slim
slim = contrib_slim
class SsdPnasNetFeatureExtractorTest(
......
......@@ -18,6 +18,7 @@ See https://arxiv.org/abs/1708.02002 for details.
"""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -26,7 +27,7 @@ from object_detection.utils import ops
from object_detection.utils import shape_utils
from nets import resnet_v1
slim = tf.contrib.slim
slim = contrib_slim
class SSDResnetV1FpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
......
......@@ -15,6 +15,7 @@
"""SSD feature extractors based on Resnet v1 and PPN architectures."""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.meta_architectures import ssd_meta_arch
from object_detection.models import feature_map_generators
......@@ -23,7 +24,7 @@ from object_detection.utils import ops
from object_detection.utils import shape_utils
from nets import resnet_v1
slim = tf.contrib.slim
slim = contrib_slim
class _SSDResnetPpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
......
......@@ -198,7 +198,7 @@ class ConvolutionalBoxPredictorTest(test_case.TestCase):
max_depth=32,
num_layers_before_predictor=1,
dropout_keep_prob=0.8,
kernel_size=1,
kernel_size=3,
box_code_size=4,
use_dropout=True,
use_depthwise=True))
......@@ -250,7 +250,7 @@ class ConvolutionalBoxPredictorTest(test_case.TestCase):
max_depth=32,
num_layers_before_predictor=1,
dropout_keep_prob=0.8,
kernel_size=1,
kernel_size=3,
box_code_size=4,
use_dropout=True,
use_depthwise=True))
......
......@@ -209,7 +209,7 @@ class ConvolutionalKerasBoxPredictorTest(test_case.TestCase):
num_layers_before_predictor=1,
use_dropout=True,
dropout_keep_prob=0.8,
kernel_size=1,
kernel_size=3,
box_code_size=4,
use_depthwise=True
))
......
......@@ -21,10 +21,11 @@ All the box prediction heads have a predict function that receives the
"""
import functools
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.predictors.heads import head
slim = tf.contrib.slim
slim = contrib_slim
class MaskRCNNBoxHead(head.Head):
......@@ -137,7 +138,11 @@ class ConvolutionalBoxHead(head.Head):
Raises:
ValueError: if min_depth > max_depth.
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(ConvolutionalBoxHead, self).__init__()
self._is_training = is_training
self._box_code_size = box_code_size
......@@ -221,7 +226,13 @@ class WeightSharedConvolutionalBoxHead(head.Head):
box_coder]. Otherwise returns the prediction tensor before reshaping,
whose shape is [batch, height, width, num_predictions_per_location *
num_class_slots].
Raises:
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(WeightSharedConvolutionalBoxHead, self).__init__()
self._box_code_size = box_code_size
self._kernel_size = kernel_size
......
......@@ -21,10 +21,11 @@ All the class prediction heads have a predict function that receives the
"""
import functools
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.predictors.heads import head
slim = tf.contrib.slim
slim = contrib_slim
class MaskRCNNClassHead(head.Head):
......@@ -143,7 +144,11 @@ class ConvolutionalClassHead(head.Head):
Raises:
ValueError: if min_depth > max_depth.
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(ConvolutionalClassHead, self).__init__()
self._is_training = is_training
self._num_class_slots = num_class_slots
......@@ -247,7 +252,13 @@ class WeightSharedConvolutionalClassHead(head.Head):
whose shape is [batch, height, width, num_predictions_per_location *
num_class_slots].
scope: Scope name for the convolution operation.
Raises:
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(WeightSharedConvolutionalClassHead, self).__init__()
self._num_class_slots = num_class_slots
self._kernel_size = kernel_size
......@@ -303,4 +314,3 @@ class WeightSharedConvolutionalClassHead(head.Head):
class_predictions_with_background,
[batch_size, -1, self._num_class_slots])
return class_predictions_with_background
......@@ -62,7 +62,11 @@ class ConvolutionalBoxHead(head.KerasHead):
Raises:
ValueError: if min_depth > max_depth.
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(ConvolutionalBoxHead, self).__init__(name=name)
self._is_training = is_training
self._box_code_size = box_code_size
......@@ -266,7 +270,13 @@ class WeightSharedConvolutionalBoxHead(head.KerasHead):
num_class_slots].
name: A string name scope to assign to the model. If `None`, Keras
will auto-generate one from the class name.
Raises:
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(WeightSharedConvolutionalBoxHead, self).__init__(name=name)
self._box_code_size = box_code_size
self._kernel_size = kernel_size
......
......@@ -71,7 +71,11 @@ class ConvolutionalClassHead(head.KerasHead):
Raises:
ValueError: if min_depth > max_depth.
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(ConvolutionalClassHead, self).__init__(name=name)
self._is_training = is_training
self._use_dropout = use_dropout
......@@ -274,7 +278,13 @@ class WeightSharedConvolutionalClassHead(head.KerasHead):
num_class_slots].
name: A string name scope to assign to the model. If `None`, Keras
will auto-generate one from the class name.
Raises:
ValueError: if use_depthwise is True and kernel_size is 1.
"""
if use_depthwise and (kernel_size == 1):
raise ValueError('Should not use 1x1 kernel when using depthwise conv')
super(WeightSharedConvolutionalClassHead, self).__init__(name=name)
self._num_class_slots = num_class_slots
self._kernel_size = kernel_size
......
......@@ -23,9 +23,10 @@ Mask RCNN paper. Or they could be used to represent different part locations of
objects.
"""
import tensorflow as tf
from tensorflow.contrib import slim as contrib_slim
from object_detection.predictors.heads import head
slim = tf.contrib.slim
slim = contrib_slim
class MaskRCNNKeypointHead(head.Head):
......
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