Python object_detection.box_coders.faster_rcnn_box_coder.FasterRcnnBoxCoder() Examples

The following are 30 code examples of object_detection.box_coders.faster_rcnn_box_coder.FasterRcnnBoxCoder(). 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.box_coders.faster_rcnn_box_coder , or try the search function .
Example #1
Source File: ssd_dataloader.py    From benchmarks with Apache License 2.0 6 votes vote down vote up
def __init__(self):
    similarity_calc = region_similarity_calculator.IouSimilarity()
    matcher = argmax_matcher.ArgMaxMatcher(
        matched_threshold=ssd_constants.MATCH_THRESHOLD,
        unmatched_threshold=ssd_constants.MATCH_THRESHOLD,
        negatives_lower_than_unmatched=True,
        force_match_for_each_row=True)

    box_coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=ssd_constants.BOX_CODER_SCALES)

    self.default_boxes = DefaultBoxes()('ltrb')
    self.default_boxes = box_list.BoxList(
        tf.convert_to_tensor(self.default_boxes))
    self.assigner = target_assigner.TargetAssigner(
        similarity_calc, matcher, box_coder) 
Example #2
Source File: faster_rcnn_box_coder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding_with_scaling(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    scale_factors = [2, 3, 4, 5]
    expected_rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                          [-0.166667, -0.666667, -2.772588, -5.493062]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #3
Source File: faster_rcnn_box_coder_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding_with_scaling(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    scale_factors = [2, 3, 4, 5]
    expected_rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                          [-0.166667, -0.666667, -2.772588, -5.493062]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #4
Source File: faster_rcnn_box_coder_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                 [-0.083333, -0.222222, -0.693147, -1.098612]]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #5
Source File: faster_rcnn_box_coder_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding_with_scaling(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                 [-0.166667, -0.666667, -2.772588, -5.493062]]
    scale_factors = [2, 3, 4, 5]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #6
Source File: faster_rcnn_box_coder_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_very_small_Width_nan_after_encoding(self):
    boxes = [[10.0, 10.0, 10.0000001, 20.0]]
    anchors = [[15.0, 12.0, 30.0, 18.0]]
    expected_rel_codes = [[-0.833333, 0., -21.128731, 0.510826]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #7
Source File: faster_rcnn_box_coder_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                 [-0.083333, -0.222222, -0.693147, -1.098612]]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #8
Source File: box_coder_builder.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def build(box_coder_config):
  """Builds a box coder object based on the box coder config.

  Args:
    box_coder_config: A box_coder.proto object containing the config for the
      desired box coder.

  Returns:
    BoxCoder based on the config.

  Raises:
    ValueError: On empty box coder proto.
  """
  if not isinstance(box_coder_config, box_coder_pb2.BoxCoder):
    raise ValueError('box_coder_config not of type box_coder_pb2.BoxCoder.')

  if box_coder_config.WhichOneof('box_coder_oneof') == 'faster_rcnn_box_coder':
    return faster_rcnn_box_coder.FasterRcnnBoxCoder(scale_factors=[
        box_coder_config.faster_rcnn_box_coder.y_scale,
        box_coder_config.faster_rcnn_box_coder.x_scale,
        box_coder_config.faster_rcnn_box_coder.height_scale,
        box_coder_config.faster_rcnn_box_coder.width_scale
    ])
  if (box_coder_config.WhichOneof('box_coder_oneof') ==
      'mean_stddev_box_coder'):
    return mean_stddev_box_coder.MeanStddevBoxCoder()
  if box_coder_config.WhichOneof('box_coder_oneof') == 'square_box_coder':
    return square_box_coder.SquareBoxCoder(scale_factors=[
        box_coder_config.square_box_coder.y_scale,
        box_coder_config.square_box_coder.x_scale,
        box_coder_config.square_box_coder.length_scale
    ])
  raise ValueError('Empty box coder.') 
Example #9
Source File: box_coder_builder_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def test_build_faster_rcnn_box_coder_with_non_default_parameters(self):
    box_coder_text_proto = """
      faster_rcnn_box_coder {
        y_scale: 6.0
        x_scale: 3.0
        height_scale: 7.0
        width_scale: 8.0
      }
    """
    box_coder_proto = box_coder_pb2.BoxCoder()
    text_format.Merge(box_coder_text_proto, box_coder_proto)
    box_coder_object = box_coder_builder.build(box_coder_proto)
    self.assertTrue(isinstance(box_coder_object,
                               faster_rcnn_box_coder.FasterRcnnBoxCoder))
    self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0]) 
Example #10
Source File: faster_rcnn_box_coder_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def test_very_small_Width_nan_after_encoding(self):
    boxes = [[10.0, 10.0, 10.0000001, 20.0]]
    anchors = [[15.0, 12.0, 30.0, 18.0]]
    expected_rel_codes = [[-0.833333, 0., -21.128731, 0.510826]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #11
Source File: faster_rcnn_box_coder_test.py    From Hands-On-Machine-Learning-with-OpenCV-4 with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding_with_scaling(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                 [-0.166667, -0.666667, -2.772588, -5.493062]]
    scale_factors = [2, 3, 4, 5]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #12
Source File: faster_rcnn_box_coder_test.py    From tensorflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    expected_rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                          [-0.083333, -0.222222, -0.693147, -1.098612]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #13
Source File: faster_rcnn_box_coder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_very_small_Width_nan_after_encoding(self):
    boxes = [[10.0, 10.0, 10.0000001, 20.0]]
    anchors = [[15.0, 12.0, 30.0, 18.0]]
    expected_rel_codes = [[-0.833333, 0., -21.128731, 0.510826]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #14
Source File: faster_rcnn_box_coder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_get_correct_boxes_after_decoding_with_scaling(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                 [-0.166667, -0.666667, -2.772588, -5.493062]]
    scale_factors = [2, 3, 4, 5]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #15
Source File: faster_rcnn_box_coder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_get_correct_boxes_after_decoding(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                 [-0.083333, -0.222222, -0.693147, -1.098612]]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #16
Source File: box_coder_builder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_build_faster_rcnn_box_coder_with_non_default_parameters(self):
    box_coder_text_proto = """
      faster_rcnn_box_coder {
        y_scale: 6.0
        x_scale: 3.0
        height_scale: 7.0
        width_scale: 8.0
      }
    """
    box_coder_proto = box_coder_pb2.BoxCoder()
    text_format.Merge(box_coder_text_proto, box_coder_proto)
    box_coder_object = box_coder_builder.build(box_coder_proto)
    self.assertIsInstance(box_coder_object,
                          faster_rcnn_box_coder.FasterRcnnBoxCoder)
    self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0]) 
Example #17
Source File: faster_rcnn_box_coder_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    expected_rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                          [-0.083333, -0.222222, -0.693147, -1.098612]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #18
Source File: box_coder_builder.py    From HereIsWally with MIT License 5 votes vote down vote up
def build(box_coder_config):
  """Builds a box coder object based on the box coder config.

  Args:
    box_coder_config: A box_coder.proto object containing the config for the
      desired box coder.

  Returns:
    BoxCoder based on the config.

  Raises:
    ValueError: On empty box coder proto.
  """
  if not isinstance(box_coder_config, box_coder_pb2.BoxCoder):
    raise ValueError('box_coder_config not of type box_coder_pb2.BoxCoder.')

  if box_coder_config.WhichOneof('box_coder_oneof') == 'faster_rcnn_box_coder':
    return faster_rcnn_box_coder.FasterRcnnBoxCoder(scale_factors=[
        box_coder_config.faster_rcnn_box_coder.y_scale,
        box_coder_config.faster_rcnn_box_coder.x_scale,
        box_coder_config.faster_rcnn_box_coder.height_scale,
        box_coder_config.faster_rcnn_box_coder.width_scale
    ])
  if (box_coder_config.WhichOneof('box_coder_oneof') ==
      'mean_stddev_box_coder'):
    return mean_stddev_box_coder.MeanStddevBoxCoder()
  if box_coder_config.WhichOneof('box_coder_oneof') == 'square_box_coder':
    return square_box_coder.SquareBoxCoder(scale_factors=[
        box_coder_config.square_box_coder.y_scale,
        box_coder_config.square_box_coder.x_scale,
        box_coder_config.square_box_coder.length_scale
    ])
  raise ValueError('Empty box coder.') 
Example #19
Source File: box_coder_builder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_build_faster_rcnn_box_coder_with_non_default_parameters(self):
    box_coder_text_proto = """
      faster_rcnn_box_coder {
        y_scale: 6.0
        x_scale: 3.0
        height_scale: 7.0
        width_scale: 8.0
      }
    """
    box_coder_proto = box_coder_pb2.BoxCoder()
    text_format.Merge(box_coder_text_proto, box_coder_proto)
    box_coder_object = box_coder_builder.build(box_coder_proto)
    self.assertTrue(isinstance(box_coder_object,
                               faster_rcnn_box_coder.FasterRcnnBoxCoder))
    self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0]) 
Example #20
Source File: faster_rcnn_box_coder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_very_small_Width_nan_after_encoding(self):
    boxes = [[10.0, 10.0, 10.0000001, 20.0]]
    anchors = [[15.0, 12.0, 30.0, 18.0]]
    expected_rel_codes = [[-0.833333, 0., -21.128731, 0.510826]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #21
Source File: faster_rcnn_box_coder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding_with_scaling(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                 [-0.166667, -0.666667, -2.772588, -5.493062]]
    scale_factors = [2, 3, 4, 5]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #22
Source File: faster_rcnn_box_coder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                 [-0.083333, -0.222222, -0.693147, -1.098612]]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #23
Source File: faster_rcnn_box_coder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding_with_scaling(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    scale_factors = [2, 3, 4, 5]
    expected_rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                          [-0.166667, -0.666667, -2.772588, -5.493062]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #24
Source File: faster_rcnn_box_coder_test.py    From HereIsWally with MIT License 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    expected_rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                          [-0.083333, -0.222222, -0.693147, -1.098612]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #25
Source File: box_coder_builder.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def build(box_coder_config):
  """Builds a box coder object based on the box coder config.

  Args:
    box_coder_config: A box_coder.proto object containing the config for the
      desired box coder.

  Returns:
    BoxCoder based on the config.

  Raises:
    ValueError: On empty box coder proto.
  """
  if not isinstance(box_coder_config, box_coder_pb2.BoxCoder):
    raise ValueError('box_coder_config not of type box_coder_pb2.BoxCoder.')

  if box_coder_config.WhichOneof('box_coder_oneof') == 'faster_rcnn_box_coder':
    return faster_rcnn_box_coder.FasterRcnnBoxCoder(scale_factors=[
        box_coder_config.faster_rcnn_box_coder.y_scale,
        box_coder_config.faster_rcnn_box_coder.x_scale,
        box_coder_config.faster_rcnn_box_coder.height_scale,
        box_coder_config.faster_rcnn_box_coder.width_scale
    ])
  if (box_coder_config.WhichOneof('box_coder_oneof') ==
      'mean_stddev_box_coder'):
    return mean_stddev_box_coder.MeanStddevBoxCoder()
  if box_coder_config.WhichOneof('box_coder_oneof') == 'square_box_coder':
    return square_box_coder.SquareBoxCoder(scale_factors=[
        box_coder_config.square_box_coder.y_scale,
        box_coder_config.square_box_coder.x_scale,
        box_coder_config.square_box_coder.length_scale
    ])
  raise ValueError('Empty box coder.') 
Example #26
Source File: box_coder_builder_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_build_faster_rcnn_box_coder_with_non_default_parameters(self):
    box_coder_text_proto = """
      faster_rcnn_box_coder {
        y_scale: 6.0
        x_scale: 3.0
        height_scale: 7.0
        width_scale: 8.0
      }
    """
    box_coder_proto = box_coder_pb2.BoxCoder()
    text_format.Merge(box_coder_text_proto, box_coder_proto)
    box_coder_object = box_coder_builder.build(box_coder_proto)
    self.assertTrue(isinstance(box_coder_object,
                               faster_rcnn_box_coder.FasterRcnnBoxCoder))
    self.assertEqual(box_coder_object._scale_factors, [6.0, 3.0, 7.0, 8.0]) 
Example #27
Source File: faster_rcnn_box_coder_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_very_small_Width_nan_after_encoding(self):
    boxes = [[10.0, 10.0, 10.0000001, 20.0]]
    anchors = [[15.0, 12.0, 30.0, 18.0]]
    expected_rel_codes = [[-0.833333, 0., -21.128731, 0.510826]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes) 
Example #28
Source File: faster_rcnn_box_coder_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding_with_scaling(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-1., -1.25, -1.62186, -0.911608],
                 [-0.166667, -0.666667, -2.772588, -5.493062]]
    scale_factors = [2, 3, 4, 5]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder(
        scale_factors=scale_factors)
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #29
Source File: faster_rcnn_box_coder_test.py    From garbage-object-detection-tensorflow with MIT License 5 votes vote down vote up
def test_get_correct_boxes_after_decoding(self):
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                 [-0.083333, -0.222222, -0.693147, -1.098612]]
    expected_boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    boxes = coder.decode(rel_codes, anchors)
    with self.test_session() as sess:
      boxes_out, = sess.run([boxes.get()])
      self.assertAllClose(boxes_out, expected_boxes) 
Example #30
Source File: faster_rcnn_box_coder_test.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def test_get_correct_relative_codes_after_encoding(self):
    boxes = [[10.0, 10.0, 20.0, 15.0], [0.2, 0.1, 0.5, 0.4]]
    anchors = [[15.0, 12.0, 30.0, 18.0], [0.1, 0.0, 0.7, 0.9]]
    expected_rel_codes = [[-0.5, -0.416666, -0.405465, -0.182321],
                          [-0.083333, -0.222222, -0.693147, -1.098612]]
    boxes = box_list.BoxList(tf.constant(boxes))
    anchors = box_list.BoxList(tf.constant(anchors))
    coder = faster_rcnn_box_coder.FasterRcnnBoxCoder()
    rel_codes = coder.encode(boxes, anchors)
    with self.test_session() as sess:
      rel_codes_out, = sess.run([rel_codes])
      self.assertAllClose(rel_codes_out, expected_rel_codes)