Python object_detection.models.feature_map_generators.pooling_pyramid_feature_maps() Examples

The following are 26 code examples of object_detection.models.feature_map_generators.pooling_pyramid_feature_maps(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module object_detection.models.feature_map_generators , or try the search function .
Example #1
Source File: feature_map_generators_test.py    From MAX-Object-Detector with Apache License 2.0 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #2
Source File: feature_map_generators_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #3
Source File: feature_map_generators_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #4
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #5
Source File: feature_map_generators_test.py    From models with Apache License 2.0 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #6
Source File: feature_map_generators_test.py    From models with Apache License 2.0 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #7
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From models with Apache License 2.0 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return list(feature_maps.values()) 
Example #8
Source File: feature_map_generators_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #9
Source File: feature_map_generators_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #10
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #11
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #12
Source File: feature_map_generators_test.py    From MAX-Object-Detector with Apache License 2.0 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #13
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From MAX-Object-Detector with Apache License 2.0 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #14
Source File: feature_map_generators_test.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #15
Source File: feature_map_generators_test.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #16
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #17
Source File: ssd_mobilenet_v1_ppn_feature_extractor.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 5 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]
    """
    preprocessed_inputs = shape_utils.check_min_image_dim(
        33, preprocessed_inputs)

    with tf.variable_scope('MobilenetV1',
                           reuse=self._reuse_weights) as scope:
      with slim.arg_scope(
          mobilenet_v1.mobilenet_v1_arg_scope(
              is_training=None, regularize_depthwise=True)):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams
              else context_manager.IdentityContextManager()):
          _, image_features = mobilenet_v1.mobilenet_v1_base(
              ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
              final_endpoint='Conv2d_13_pointwise',
              min_depth=self._min_depth,
              depth_multiplier=self._depth_multiplier,
              use_explicit_padding=self._use_explicit_padding,
              scope=scope)
      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=0,
            num_layers=6,
            image_features={
                'image_features': image_features['Conv2d_11_pointwise']
            })
    return feature_maps.values() 
Example #18
Source File: feature_map_generators_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def test_get_expected_variable_names(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
    ])

    expected_conv_variables = set([
        'Base_Conv2d_1x1_1024/weights',
        'Base_Conv2d_1x1_1024/biases',
        'Conv2d_0_3x3_s2_1024/weights',
        'Conv2d_0_3x3_s2_1024/biases',
        'Conv2d_1_3x3_s2_1024/weights',
        'Conv2d_1_3x3_s2_1024/biases',
        'Conv2d_2_3x3_s2_1024/weights',
        'Conv2d_2_3x3_s2_1024/biases',
        'Conv2d_3_3x3_s2_1024/weights',
        'Conv2d_3_3x3_s2_1024/biases',
        'Conv2d_4_3x3_s2_1024/weights',
        'Conv2d_4_3x3_s2_1024/biases',
    ])

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      sess.run(feature_maps)
      actual_variable_set = set(
          [var.op.name for var in tf.trainable_variables()])
      if replace_pool_with_conv:
        self.assertSetEqual(expected_conv_variables, actual_variable_set)
      else:
        self.assertSetEqual(expected_pool_variables, actual_variable_set) 
Example #19
Source File: feature_map_generators_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def test_get_expected_feature_map_shapes(self, replace_pool_with_conv):
    image_features = {
        'image_features': tf.random_uniform([4, 19, 19, 1024])
    }
    feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
        base_feature_map_depth=1024,
        num_layers=6,
        image_features=image_features,
        replace_pool_with_conv=replace_pool_with_conv)

    expected_pool_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'MaxPool2d_0_2x2': (4, 10, 10, 1024),
        'MaxPool2d_1_2x2': (4, 5, 5, 1024),
        'MaxPool2d_2_2x2': (4, 3, 3, 1024),
        'MaxPool2d_3_2x2': (4, 2, 2, 1024),
        'MaxPool2d_4_2x2': (4, 1, 1, 1024),
    }

    expected_conv_feature_map_shapes = {
        'Base_Conv2d_1x1_1024': (4, 19, 19, 1024),
        'Conv2d_0_3x3_s2_1024': (4, 10, 10, 1024),
        'Conv2d_1_3x3_s2_1024': (4, 5, 5, 1024),
        'Conv2d_2_3x3_s2_1024': (4, 3, 3, 1024),
        'Conv2d_3_3x3_s2_1024': (4, 2, 2, 1024),
        'Conv2d_4_3x3_s2_1024': (4, 1, 1, 1024),
    }

    init_op = tf.global_variables_initializer()
    with self.test_session() as sess:
      sess.run(init_op)
      out_feature_maps = sess.run(feature_maps)
      out_feature_map_shapes = {key: value.shape
                                for key, value in out_feature_maps.items()}
      if replace_pool_with_conv:
        self.assertDictEqual(expected_conv_feature_map_shapes,
                             out_feature_map_shapes)
      else:
        self.assertDictEqual(expected_pool_feature_map_shapes,
                             out_feature_map_shapes) 
Example #20
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From MAX-Object-Detector with Apache License 2.0 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values() 
Example #21
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From g-tensorflow-models with Apache License 2.0 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values() 
Example #22
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values() 
Example #23
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From models with Apache License 2.0 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return list(feature_maps.values()) 
Example #24
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From BMW-TensorFlow-Training-GUI with Apache License 2.0 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values() 
Example #25
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From multilabel-image-classification-tensorflow with MIT License 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values() 
Example #26
Source File: ssd_resnet_v1_ppn_feature_extractor.py    From vehicle_counting_tensorflow with MIT License 4 votes vote down vote up
def extract_features(self, preprocessed_inputs):
    """Extract features from preprocessed inputs.

    Args:
      preprocessed_inputs: a [batch, height, width, channels] float tensor
        representing a batch of images.

    Returns:
      feature_maps: a list of tensors where the ith tensor has shape
        [batch, height_i, width_i, depth_i]

    Raises:
      ValueError: depth multiplier is not supported.
    """
    if self._depth_multiplier != 1.0:
      raise ValueError('Depth multiplier not supported.')

    preprocessed_inputs = shape_utils.check_min_image_dim(
        129, preprocessed_inputs)

    with tf.variable_scope(
        self._resnet_scope_name, reuse=self._reuse_weights) as scope:
      with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with (slim.arg_scope(self._conv_hyperparams_fn())
              if self._override_base_feature_extractor_hyperparams else
              context_manager.IdentityContextManager()):
          with slim.arg_scope(
              [resnet_v1.bottleneck],
              use_bounded_activations=self._use_bounded_activations):
            _, activations = self._resnet_base_fn(
                inputs=ops.pad_to_multiple(preprocessed_inputs,
                                           self._pad_to_multiple),
                num_classes=None,
                is_training=None,
                global_pool=False,
                output_stride=None,
                store_non_strided_activations=True,
                scope=scope)

      with slim.arg_scope(self._conv_hyperparams_fn()):
        feature_maps = feature_map_generators.pooling_pyramid_feature_maps(
            base_feature_map_depth=self._base_feature_map_depth,
            num_layers=self._num_layers,
            image_features={
                'image_features': self._filter_features(activations)['block3']
            })
    return feature_maps.values()