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