Unverified Commit 451906e4 authored by pkulzc's avatar pkulzc Committed by GitHub
Browse files

Release MobileDet code and model, and require tf_slim installation for OD API. (#8562)



* Merged commit includes the following changes:
311933687  by Sergio Guadarrama:

    Removes spurios use of tf.compat.v2, which results in spurious tf.compat.v1.compat.v2. Adds basic test to nasnet_utils.
    Replaces all remaining import tensorflow as tf with import tensorflow.compat.v1 as tf

--
311766063  by Sergio Guadarrama:

    Removes explicit tf.compat.v1 in all call sites (we already import tf.compat.v1, so this code was  doing tf.compat.v1.compat.v1). The existing code worked in latest version of tensorflow, 2.2, (and 1.15) but not in 1.14 or in 2.0.0a, this CL fixes it.

--
311624958  by Sergio Guadarrama:

    Updates README that doesn't render properly in github documentation

--
310980959  by Sergio Guadarrama:

    Moves research_models/slim off tf.contrib.slim/layers/framework to tf_slim

--
310263156  by Sergio Guadarrama:

    Adds model breakdown for MobilenetV3

--
308640516  by Sergio Guadarrama:

    Internal change

308244396  by Sergio Guadarrama:

    GroupNormalization support for MobilenetV3.

--
307475800  by Sergio Guadarrama:

    Internal change

--
302077708  by Sergio Guadarrama:

    Remove `disable_tf2` behavior from slim py_library targets

--
301208453  by Sergio Guadarrama:

    Automated refactoring to make code Python 3 compatible.

--
300816672  by Sergio Guadarrama:

    Internal change

299433840  by Sergio Guadarrama:

    Internal change

299221609  by Sergio Guadarrama:

    Explicitly disable Tensorflow v2 behaviors for all TF1.x binaries and tests

--
299179617  by Sergio Guadarrama:

    Internal change

299040784  by Sergio Guadarrama:

    Internal change

299036699  by Sergio Guadarrama:

    Internal change

298736510  by Sergio Guadarrama:

    Internal change

298732599  by Sergio Guadarrama:

    Internal change

298729507  by Sergio Guadarrama:

    Internal change

298253328  by Sergio Guadarrama:

    Internal change

297788346  by Sergio Guadarrama:

    Internal change

297785278  by Sergio Guadarrama:

    Internal change

297783127  by Sergio Guadarrama:

    Internal change

297725870  by Sergio Guadarrama:

    Internal change

297721811  by Sergio Guadarrama:

    Internal change

297711347  by Sergio Guadarrama:

    Internal change

297708059  by Sergio Guadarrama:

    Internal change

297701831  by Sergio Guadarrama:

    Internal change

297700038  by Sergio Guadarrama:

    Internal change

297670468  by Sergio Guadarrama:

    Internal change.

--
297350326  by Sergio Guadarrama:

    Explicitly replace "import tensorflow" with "tensorflow.compat.v1" for TF2.x migration

--
297201668  by Sergio Guadarrama:

    Explicitly replace "import tensorflow" with "tensorflow.compat.v1" for TF2.x migration

--
294483372  by Sergio Guadarrama:

    Internal change

PiperOrigin-RevId: 311933687

* Merged commit includes the following changes:
312578615  by Menglong Zhu:

    Modify the LSTM feature extractors to be python 3 compatible.

--
311264357  by Menglong Zhu:

    Removes contrib.slim

--
308957207  by Menglong Zhu:

    Automated refactoring to make code Python 3 compatible.

--
306976470  by yongzhe:

    Internal change

306777559  by Menglong Zhu:

    Internal change

--
299232507  by lzyuan:

    Internal update.

--
299221735  by lzyuan:

    Add small epsilon on max_range for quantize_op to prevent range collapse.

--

PiperOrigin-RevId: 312578615

* Merged commit includes the following changes:
310447280  by lzc:

    Internal changes.

--

PiperOrigin-RevId: 310447280
Co-authored-by: default avatarSergio Guadarrama <sguada@google.com>
Co-authored-by: default avatarMenglong Zhu <menglong@google.com>
parent 73b5be67
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"""SSDFeatureExtractor for MobilenetV2 features.""" """SSDFeatureExtractor for MobilenetV2 features."""
import tensorflow as tf import tensorflow.compat.v1 as tf
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
......
...@@ -22,16 +22,15 @@ from __future__ import print_function ...@@ -22,16 +22,15 @@ from __future__ import print_function
import collections import collections
import functools import functools
from six.moves import range from six.moves import range
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as slim
from object_detection.meta_architectures import ssd_meta_arch from object_detection.meta_architectures import ssd_meta_arch
from object_detection.utils import ops from object_detection.utils import ops
from object_detection.utils import shape_utils 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 = contrib_slim
Block = collections.namedtuple( Block = collections.namedtuple(
'Block', ['inputs', 'output_level', 'kernel_size', 'expansion_size']) 'Block', ['inputs', 'output_level', 'kernel_size', 'expansion_size'])
......
...@@ -15,14 +15,11 @@ ...@@ -15,14 +15,11 @@
# ============================================================================== # ==============================================================================
"""Tests for ssd_mobilenet_v2_nas_fpn_feature_extractor.""" """Tests for ssd_mobilenet_v2_nas_fpn_feature_extractor."""
import numpy as np import numpy as np
import tensorflow as tf import tensorflow.compat.v1 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_mnasfpn_feature_extractor as mnasfpn_feature_extractor from object_detection.models import ssd_mobilenet_v2_mnasfpn_feature_extractor as mnasfpn_feature_extractor
slim = contrib_slim
class SsdMobilenetV2MnasFPNFeatureExtractorTest( class SsdMobilenetV2MnasFPNFeatureExtractorTest(
ssd_feature_extractor_test.SsdFeatureExtractorTestBase): ssd_feature_extractor_test.SsdFeatureExtractorTestBase):
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
# ============================================================================== # ==============================================================================
"""SSDFeatureExtractor for MobileNetV3 features.""" """SSDFeatureExtractor for MobileNetV3 features."""
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as 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,8 +25,6 @@ from object_detection.utils import shape_utils ...@@ -25,8 +25,6 @@ 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 = 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."""
......
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
# ============================================================================== # ==============================================================================
"""Tests for ssd_mobilenet_v3_feature_extractor.""" """Tests for ssd_mobilenet_v3_feature_extractor."""
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as 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 = contrib_slim slim = slim
class SsdMobilenetV3LargeFeatureExtractorTest( class SsdMobilenetV3LargeFeatureExtractorTest(
......
...@@ -17,15 +17,11 @@ ...@@ -17,15 +17,11 @@
import abc import abc
import numpy as np import numpy as np
import tensorflow as tf import tensorflow.compat.v1 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 = contrib_slim
class _SsdMobilenetV3FeatureExtractorTestBase( class _SsdMobilenetV3FeatureExtractorTestBase(
ssd_feature_extractor_test.SsdFeatureExtractorTestBase): ssd_feature_extractor_test.SsdFeatureExtractorTestBase):
"""Base class for MobilenetV3 tests.""" """Base class for MobilenetV3 tests."""
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
Based on PNASNet ImageNet model: https://arxiv.org/abs/1712.00559 Based on PNASNet ImageNet model: https://arxiv.org/abs/1712.00559
""" """
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as 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
...@@ -29,8 +29,6 @@ from object_detection.utils import ops ...@@ -29,8 +29,6 @@ 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 = 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):
"""Defines the default arg scope for the PNASNet Large for object detection. """Defines the default arg scope for the PNASNet Large for object detection.
......
...@@ -15,14 +15,11 @@ ...@@ -15,14 +15,11 @@
"""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.compat.v1 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 = contrib_slim
class SsdPnasNetFeatureExtractorTest( class SsdPnasNetFeatureExtractorTest(
ssd_feature_extractor_test.SsdFeatureExtractorTestBase): ssd_feature_extractor_test.SsdFeatureExtractorTestBase):
......
...@@ -23,8 +23,8 @@ from __future__ import division ...@@ -23,8 +23,8 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
from six.moves import range from six.moves import range
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as 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
...@@ -33,8 +33,6 @@ from object_detection.utils import ops ...@@ -33,8 +33,6 @@ 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 = contrib_slim
class SSDResnetV1FpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor): class SSDResnetV1FpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
"""SSD FPN feature extractor based on Resnet v1 architecture.""" """SSD FPN feature extractor based on Resnet v1 architecture."""
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
# ============================================================================== # ==============================================================================
"""Tests for ssd resnet v1 FPN feature extractors.""" """Tests for ssd resnet v1 FPN feature extractors."""
import tensorflow as tf import tensorflow.compat.v1 as tf
from object_detection.models import ssd_resnet_v1_fpn_feature_extractor from object_detection.models import ssd_resnet_v1_fpn_feature_extractor
from object_detection.models import ssd_resnet_v1_fpn_feature_extractor_testbase from object_detection.models import ssd_resnet_v1_fpn_feature_extractor_testbase
......
...@@ -22,7 +22,7 @@ import abc ...@@ -22,7 +22,7 @@ import abc
from absl.testing import parameterized from absl.testing import parameterized
import numpy as np import numpy as np
from six.moves import zip from six.moves import zip
import tensorflow as tf import tensorflow.compat.v1 as tf
from object_detection.models import ssd_feature_extractor_test from object_detection.models import ssd_feature_extractor_test
......
...@@ -22,7 +22,7 @@ from __future__ import print_function ...@@ -22,7 +22,7 @@ from __future__ import print_function
from six.moves import range from six.moves import range
from six.moves import zip from six.moves import zip
import tensorflow as tf import tensorflow.compat.v1 as tf
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
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
# ============================================================================== # ==============================================================================
"""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.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as 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,8 +25,6 @@ from object_detection.utils import ops ...@@ -25,8 +25,6 @@ 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 = contrib_slim
class _SSDResnetPpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor): class _SSDResnetPpnFeatureExtractor(ssd_meta_arch.SSDFeatureExtractor):
"""SSD feature extractor based on resnet architecture and PPN.""" """SSD feature extractor based on resnet architecture and PPN."""
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
# ============================================================================== # ==============================================================================
"""Tests for ssd resnet v1 feature extractors.""" """Tests for ssd resnet v1 feature extractors."""
import tensorflow as tf import tensorflow.compat.v1 as tf
from object_detection.models import ssd_resnet_v1_ppn_feature_extractor from object_detection.models import ssd_resnet_v1_ppn_feature_extractor
from object_detection.models import ssd_resnet_v1_ppn_feature_extractor_testbase from object_detection.models import ssd_resnet_v1_ppn_feature_extractor_testbase
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"""Tests for ssd resnet v1 feature extractors.""" """Tests for ssd resnet v1 feature extractors."""
import abc import abc
import numpy as np import numpy as np
import tensorflow as tf import tensorflow.compat.v1 as tf
from object_detection.models import ssd_feature_extractor_test from object_detection.models import ssd_feature_extractor_test
......
...@@ -21,14 +21,12 @@ from __future__ import print_function ...@@ -21,14 +21,12 @@ from __future__ import print_function
import functools import functools
from six.moves import range from six.moves import range
from six.moves import zip from six.moves import zip
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as slim
from object_detection.core import box_predictor from object_detection.core import box_predictor
from object_detection.utils import shape_utils from object_detection.utils import shape_utils
from object_detection.utils import static_shape from object_detection.utils import static_shape
slim = contrib_slim
BOX_ENCODINGS = box_predictor.BOX_ENCODINGS BOX_ENCODINGS = box_predictor.BOX_ENCODINGS
CLASS_PREDICTIONS_WITH_BACKGROUND = ( CLASS_PREDICTIONS_WITH_BACKGROUND = (
box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND) box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND)
......
...@@ -24,7 +24,7 @@ from absl.testing import parameterized ...@@ -24,7 +24,7 @@ from absl.testing import parameterized
import numpy as np import numpy as np
from six.moves import range from six.moves import range
from six.moves import zip from six.moves import zip
import tensorflow as tf import tensorflow.compat.v1 as tf
from google.protobuf import text_format from google.protobuf import text_format
from object_detection.builders import box_predictor_builder from object_detection.builders import box_predictor_builder
......
...@@ -22,7 +22,7 @@ from __future__ import print_function ...@@ -22,7 +22,7 @@ from __future__ import print_function
import collections import collections
from six.moves import range from six.moves import range
import tensorflow as tf import tensorflow.compat.v1 as tf
from object_detection.core import box_predictor from object_detection.core import box_predictor
from object_detection.utils import shape_utils from object_detection.utils import shape_utils
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"""Tests for object_detection.predictors.convolutional_keras_box_predictor.""" """Tests for object_detection.predictors.convolutional_keras_box_predictor."""
import numpy as np import numpy as np
import tensorflow as tf import tensorflow.compat.v1 as tf
from google.protobuf import text_format from google.protobuf import text_format
from object_detection.builders import box_predictor_builder from object_detection.builders import box_predictor_builder
......
...@@ -20,13 +20,11 @@ All the box prediction heads have a predict function that receives the ...@@ -20,13 +20,11 @@ All the box prediction heads have a predict function that receives the
`features` as the first argument and returns `box_encodings`. `features` as the first argument and returns `box_encodings`.
""" """
import functools import functools
import tensorflow as tf import tensorflow.compat.v1 as tf
from tensorflow.contrib import slim as contrib_slim import tf_slim as slim
from object_detection.predictors.heads import head from object_detection.predictors.heads import head
slim = contrib_slim
class MaskRCNNBoxHead(head.Head): class MaskRCNNBoxHead(head.Head):
"""Box prediction head. """Box prediction 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