Python object_detection.builders.anchor_generator_builder.build() Examples

The following are 30 code examples of object_detection.builders.anchor_generator_builder.build(). 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.builders.anchor_generator_builder , or try the search function .
Example #1
Source File: model_builder.py    From HereIsWally with MIT License 6 votes vote down vote up
def build(model_config, is_training):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #2
Source File: anchor_generator_builder_test.py    From garbage-object-detection-tensorflow with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #3
Source File: model_builder.py    From Traffic-Rule-Violation-Detection-System with MIT License 6 votes vote down vote up
def build(model_config, is_training, add_summaries=True):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.
    add_summaries: Whether to add tensorflow summaries in the model graph.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training, add_summaries)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training,
                                    add_summaries)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #4
Source File: anchor_generator_builder_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_interpolated_scale(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [0.5]
        interpolated_scale_aspect_ratio: 0.5
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_aspect_ratio, expected_aspect_ratio in zip(
        list(anchor_generator_object._aspect_ratios),
        6 * [(0.5, 0.5)]):
      self.assert_almost_list_equal(expected_aspect_ratio, actual_aspect_ratio) 
Example #5
Source File: anchor_generator_builder_test.py    From yolo_v2 with Apache License 2.0 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_interpolated_scale(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [0.5]
        interpolated_scale_aspect_ratio: 0.5
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_aspect_ratio, expected_aspect_ratio in zip(
        list(anchor_generator_object._aspect_ratios),
        6 * [(0.5, 0.5)]):
      self.assert_almost_list_equal(expected_aspect_ratio, actual_aspect_ratio) 
Example #6
Source File: anchor_generator_builder_test.py    From object_detector_app with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #7
Source File: anchor_generator_builder_test.py    From yolo_v2 with Apache License 2.0 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_scales(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [1.0]
        scales: [0.1, 0.15, 0.2, 0.4, 0.6, 0.8]
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_scales, expected_scales in zip(
        list(anchor_generator_object._scales),
        [(0.1, math.sqrt(0.1 * 0.15)),
         (0.15, math.sqrt(0.15 * 0.2)),
         (0.2, math.sqrt(0.2 * 0.4)),
         (0.4, math.sqrt(0.4 * 0.6)),
         (0.6, math.sqrt(0.6 * 0.8)),
         (0.8, math.sqrt(0.8 * 1.0))]):
      self.assert_almost_list_equal(expected_scales, actual_scales, delta=1e-2) 
Example #8
Source File: anchor_generator_builder_test.py    From Traffic-Rule-Violation-Detection-System with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #9
Source File: model_builder.py    From garbage-object-detection-tensorflow with MIT License 6 votes vote down vote up
def build(model_config, is_training):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #10
Source File: anchor_generator_builder_test.py    From Traffic-Rule-Violation-Detection-System with MIT License 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_scales(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [1.0]
        scales: [0.1, 0.15, 0.2, 0.4, 0.6, 0.8]
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_scales, expected_scales in zip(
        list(anchor_generator_object._scales),
        [(0.1, math.sqrt(0.1 * 0.15)),
         (0.15, math.sqrt(0.15 * 0.2)),
         (0.2, math.sqrt(0.2 * 0.4)),
         (0.4, math.sqrt(0.4 * 0.6)),
         (0.6, math.sqrt(0.6 * 0.8)),
         (0.8, math.sqrt(0.8 * 1.0))]):
      self.assert_almost_list_equal(expected_scales, actual_scales, delta=1e-2) 
Example #11
Source File: anchor_generator_builder_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #12
Source File: anchor_generator_builder_test.py    From Traffic-Rule-Violation-Detection-System with MIT License 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_interpolated_scale(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [0.5]
        interpolated_scale_aspect_ratio: 0.5
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_aspect_ratio, expected_aspect_ratio in zip(
        list(anchor_generator_object._aspect_ratios),
        6 * [(0.5, 0.5)]):
      self.assert_almost_list_equal(expected_aspect_ratio, actual_aspect_ratio) 
Example #13
Source File: anchor_generator_builder_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def test_build_multiscale_anchor_generator_custom_aspect_ratios(self):
    anchor_generator_text_proto = """
      multiscale_anchor_generator {
        aspect_ratios: [1.0]
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiscale_grid_anchor_generator.
                               MultiscaleGridAnchorGenerator))
    for level, anchor_grid_info in zip(
        range(3, 8), anchor_generator_object._anchor_grid_info):
      self.assertEqual(set(anchor_grid_info.keys()), set(['level', 'info']))
      self.assertTrue(level, anchor_grid_info['level'])
      self.assertEqual(len(anchor_grid_info['info']), 4)
      self.assertAllClose(anchor_grid_info['info'][0], [2**0, 2**0.5])
      self.assertTrue(anchor_grid_info['info'][1], 1.0)
      self.assertAllClose(anchor_grid_info['info'][2],
                          [4.0 * 2**level, 4.0 * 2**level])
      self.assertAllClose(anchor_grid_info['info'][3], [2**level, 2**level])
      self.assertTrue(anchor_generator_object._normalize_coordinates) 
Example #14
Source File: model_builder.py    From object_detector_app with MIT License 6 votes vote down vote up
def build(model_config, is_training):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #15
Source File: model_builder.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def build(model_config, is_training):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #16
Source File: model_builder.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def build(model_config, is_training, add_summaries=True):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.
    add_summaries: Whether to add tensorflow summaries in the model graph.
  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training, add_summaries)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training,
                                    add_summaries)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #17
Source File: anchor_generator_builder_test.py    From yolo_v2 with Apache License 2.0 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #18
Source File: anchor_generator_builder_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_scales(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [1.0]
        scales: [0.1, 0.15, 0.2, 0.4, 0.6, 0.8]
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_scales, expected_scales in zip(
        list(anchor_generator_object._scales),
        [(0.1, math.sqrt(0.1 * 0.15)),
         (0.15, math.sqrt(0.15 * 0.2)),
         (0.2, math.sqrt(0.2 * 0.4)),
         (0.4, math.sqrt(0.4 * 0.6)),
         (0.6, math.sqrt(0.6 * 0.8)),
         (0.8, math.sqrt(0.8 * 1.0))]):
      self.assert_almost_list_equal(expected_scales, actual_scales, delta=1e-2) 
Example #19
Source File: model_builder.py    From yolo_v2 with Apache License 2.0 6 votes vote down vote up
def build(model_config, is_training):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #20
Source File: anchor_generator_builder_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #21
Source File: anchor_generator_builder_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_build_multiscale_anchor_generator_custom_aspect_ratios(self):
    anchor_generator_text_proto = """
      multiscale_anchor_generator {
        aspect_ratios: [1.0]
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiscale_grid_anchor_generator.
                               MultiscaleGridAnchorGenerator))
    for level, anchor_grid_info in zip(
        range(3, 8), anchor_generator_object._anchor_grid_info):
      self.assertEqual(set(anchor_grid_info.keys()), set(['level', 'info']))
      self.assertTrue(level, anchor_grid_info['level'])
      self.assertEqual(len(anchor_grid_info['info']), 4)
      self.assertAllClose(anchor_grid_info['info'][0], [2**0, 2**0.5])
      self.assertTrue(anchor_grid_info['info'][1], 1.0)
      self.assertAllClose(anchor_grid_info['info'][2],
                          [4.0 * 2**level, 4.0 * 2**level])
      self.assertAllClose(anchor_grid_info['info'][3], [2**level, 2**level])
      self.assertTrue(anchor_generator_object._normalize_coordinates) 
Example #22
Source File: anchor_generator_builder_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_build_multiscale_anchor_generator_with_anchors_in_pixel_coordinates(
      self):
    anchor_generator_text_proto = """
      multiscale_anchor_generator {
        aspect_ratios: [1.0]
        normalize_coordinates: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiscale_grid_anchor_generator.
                               MultiscaleGridAnchorGenerator))
    self.assertFalse(anchor_generator_object._normalize_coordinates) 
Example #23
Source File: model_builder.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def build(model_config, is_training, add_summaries=True):
  """Builds a DetectionModel based on the model config.

  Args:
    model_config: A model.proto object containing the config for the desired
      DetectionModel.
    is_training: True if this model is being built for training purposes.
    add_summaries: Whether to add tensorflow summaries in the model graph.

  Returns:
    DetectionModel based on the config.

  Raises:
    ValueError: On invalid meta architecture or model.
  """
  if not isinstance(model_config, model_pb2.DetectionModel):
    raise ValueError('model_config not of type model_pb2.DetectionModel.')
  meta_architecture = model_config.WhichOneof('model')
  if meta_architecture == 'ssd':
    return _build_ssd_model(model_config.ssd, is_training, add_summaries)
  if meta_architecture == 'faster_rcnn':
    return _build_faster_rcnn_model(model_config.faster_rcnn, is_training,
                                    add_summaries)
  raise ValueError('Unknown meta architecture: {}'.format(meta_architecture)) 
Example #24
Source File: anchor_generator_builder_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #25
Source File: anchor_generator_builder_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_build_multiscale_anchor_generator_custom_aspect_ratios(self):
    anchor_generator_text_proto = """
      multiscale_anchor_generator {
        aspect_ratios: [1.0]
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiscale_grid_anchor_generator.
                               MultiscaleGridAnchorGenerator))
    for level, anchor_grid_info in zip(
        range(3, 8), anchor_generator_object._anchor_grid_info):
      self.assertEqual(set(anchor_grid_info.keys()), set(['level', 'info']))
      self.assertTrue(level, anchor_grid_info['level'])
      self.assertEqual(len(anchor_grid_info['info']), 4)
      self.assertAllClose(anchor_grid_info['info'][0], [2**0, 2**0.5])
      self.assertTrue(anchor_grid_info['info'][1], 1.0)
      self.assertAllClose(anchor_grid_info['info'][2],
                          [4.0 * 2**level, 4.0 * 2**level])
      self.assertAllClose(anchor_grid_info['info'][3], [2**level, 2**level])
      self.assertTrue(anchor_generator_object._normalize_coordinates) 
Example #26
Source File: anchor_generator_builder_test.py    From HereIsWally with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #27
Source File: anchor_generator_builder_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_build_ssd_anchor_generator_with_custom_interpolated_scale(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        aspect_ratios: [0.5]
        interpolated_scale_aspect_ratio: 0.5
        reduce_boxes_in_lowest_layer: false
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))
    for actual_aspect_ratio, expected_aspect_ratio in zip(
        list(anchor_generator_object._aspect_ratios),
        6 * [(0.5, 0.5)]):
      self.assert_almost_list_equal(expected_aspect_ratio, actual_aspect_ratio) 
Example #28
Source File: anchor_generator_builder_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_build_grid_anchor_generator_with_defaults(self):
    anchor_generator_text_proto = """
      grid_anchor_generator {
      }
     """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               grid_anchor_generator.GridAnchorGenerator))
    self.assertListEqual(anchor_generator_object._scales, [])
    self.assertListEqual(anchor_generator_object._aspect_ratios, [])
    with self.test_session() as sess:
      base_anchor_size, anchor_offset, anchor_stride = sess.run(
          [anchor_generator_object._base_anchor_size,
           anchor_generator_object._anchor_offset,
           anchor_generator_object._anchor_stride])
    self.assertAllEqual(anchor_offset, [0, 0])
    self.assertAllEqual(anchor_stride, [16, 16])
    self.assertAllEqual(base_anchor_size, [256, 256]) 
Example #29
Source File: anchor_generator_builder_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_raise_value_error_on_empty_anchor_genertor(self):
    anchor_generator_text_proto = """
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    with self.assertRaises(ValueError):
      anchor_generator_builder.build(anchor_generator_proto) 
Example #30
Source File: anchor_generator_builder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_build_ssd_anchor_generator_with_non_default_parameters(self):
    anchor_generator_text_proto = """
      ssd_anchor_generator {
        num_layers: 2
        min_scale: 0.3
        max_scale: 0.8
        aspect_ratios: [2.0]
      }
    """
    anchor_generator_proto = anchor_generator_pb2.AnchorGenerator()
    text_format.Merge(anchor_generator_text_proto, anchor_generator_proto)
    anchor_generator_object = anchor_generator_builder.build(
        anchor_generator_proto)
    self.assertTrue(isinstance(anchor_generator_object,
                               multiple_grid_anchor_generator.
                               MultipleGridAnchorGenerator))

    for actual_scales, expected_scales in zip(
        list(anchor_generator_object._scales),
        [(0.1, 0.3, 0.3), (0.8,)]):
      self.assert_almost_list_equal(expected_scales, actual_scales, delta=1e-2)

    for actual_aspect_ratio, expected_aspect_ratio in zip(
        list(anchor_generator_object._aspect_ratios),
        [(1.0, 2.0, 0.5), (2.0,)]):
      self.assert_almost_list_equal(expected_aspect_ratio, actual_aspect_ratio)

    with self.test_session() as sess:
      base_anchor_size = sess.run(anchor_generator_object._base_anchor_size)
    self.assertAllClose(base_anchor_size, [1.0, 1.0])