Python object_detection.protos.anchor_generator_pb2.AnchorGenerator() Examples

The following are 30 code examples of object_detection.protos.anchor_generator_pb2.AnchorGenerator(). 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.protos.anchor_generator_pb2 , or try the search function .
Example #1
Source File: anchor_generator_builder_test.py    From Gun-Detector 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 #2
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 #3
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 #4
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 #5
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 #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 vehicle_counting_tensorflow 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 #8
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 #9
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_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 #10
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 #11
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 #12
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_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 #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_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 #14
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_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 #15
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 #16
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 #17
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_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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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_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))
    print anchor_generator_object._anchor_grid_info
    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]) 
Example #27
Source File: anchor_generator_builder_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 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 #28
Source File: anchor_generator_builder_test.py    From tensorflow with BSD 2-Clause "Simplified" 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 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 #30
Source File: anchor_generator_builder_test.py    From yolo_v2 with Apache License 2.0 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)