Python object_detection.matchers.argmax_matcher.ArgMaxMatcher() Examples

The following are 30 code examples of object_detection.matchers.argmax_matcher.ArgMaxMatcher(). 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.matchers.argmax_matcher , or try the search function .
Example #1
Source File: argmax_matcher_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_with_default_thresholds(self):
    similarity = np.array([[1., 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]])

    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
    expected_matched_rows = np.array([2, 0, 1, 0, 1])

    sim = tf.constant(similarity)
    match = matcher.match(sim)
    matched_cols = match.matched_column_indices()
    matched_rows = match.matched_row_indices()
    unmatched_cols = match.unmatched_column_indices()

    with self.test_session() as sess:
      res_matched_cols = sess.run(matched_cols)
      res_matched_rows = sess.run(matched_rows)
      res_unmatched_cols = sess.run(unmatched_cols)

    self.assertAllEqual(res_matched_rows, expected_matched_rows)
    self.assertAllEqual(res_matched_cols, np.arange(similarity.shape[1]))
    self.assertEmpty(res_unmatched_cols) 
Example #2
Source File: argmax_matcher_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_with_default_thresholds(self):

    def graph_fn(similarity_matrix):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
      match = matcher.match(similarity_matrix)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1., 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_rows = np.array([2, 0, 1, 0, 1])
    (res_matched_cols, res_unmatched_cols,
     res_match_results) = self.execute(graph_fn, [similarity])

    self.assertAllEqual(res_match_results[res_matched_cols],
                        expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], [0, 1, 2, 3, 4])
    self.assertFalse(np.all(res_unmatched_cols)) 
Example #3
Source File: argmax_matcher_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_with_matched_threshold(self):

    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1, 2])

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #4
Source File: argmax_matcher_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_with_matched_and_unmatched_threshold(self):

    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.,
                                             unmatched_threshold=2.)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1])  # col 2 has too high maximum val

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #5
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 #6
Source File: argmax_matcher_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_unmatched_row_while_using_force_match(self):
    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.,
                                             unmatched_threshold=2.,
                                             force_match_for_each_row=True)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [-1, 0, -2, -2, -1],
                           [3, 0, -1, 2, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 1, 3])
    expected_matched_rows = np.array([2, 1, 0])
    expected_unmatched_cols = np.array([2, 4])  # col 2 has too high max val

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #7
Source File: argmax_matcher_test.py    From object_detector_app with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_matched_and_unmatched_threshold(self):
    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.int32)

    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3,
                                           unmatched_threshold=2)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1])  # col 2 has too high maximum val

    sim = tf.constant(similarity)
    match = matcher.match(sim)
    matched_cols = match.matched_column_indices()
    matched_rows = match.matched_row_indices()
    unmatched_cols = match.unmatched_column_indices()

    with self.test_session() as sess:
      res_matched_cols = sess.run(matched_cols)
      res_matched_rows = sess.run(matched_rows)
      res_unmatched_cols = sess.run(unmatched_cols)

    self.assertAllEqual(res_matched_rows, expected_matched_rows)
    self.assertAllEqual(res_matched_cols, expected_matched_cols)
    self.assertAllEqual(res_unmatched_cols, expected_unmatched_cols) 
Example #8
Source File: matcher_builder_test.py    From object_detector_app with MIT License 6 votes vote down vote up
def test_build_arg_max_matcher_with_non_default_parameters(self):
    matcher_text_proto = """
      argmax_matcher {
        matched_threshold: 0.7
        unmatched_threshold: 0.3
        negatives_lower_than_unmatched: false
        force_match_for_each_row: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertAlmostEqual(matcher_object._matched_threshold, 0.7)
    self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.3)
    self.assertFalse(matcher_object._negatives_lower_than_unmatched)
    self.assertTrue(matcher_object._force_match_for_each_row) 
Example #9
Source File: matcher_builder_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_build_arg_max_matcher_with_non_default_parameters(self):
    matcher_text_proto = """
      argmax_matcher {
        matched_threshold: 0.7
        unmatched_threshold: 0.3
        negatives_lower_than_unmatched: false
        force_match_for_each_row: true
        use_matmul_gather: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertAlmostEqual(matcher_object._matched_threshold, 0.7)
    self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.3)
    self.assertFalse(matcher_object._negatives_lower_than_unmatched)
    self.assertTrue(matcher_object._force_match_for_each_row)
    self.assertTrue(matcher_object._use_matmul_gather) 
Example #10
Source File: argmax_matcher_test.py    From object_detector_app with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_default_thresholds(self):
    similarity = np.array([[1., 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]])

    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
    expected_matched_rows = np.array([2, 0, 1, 0, 1])

    sim = tf.constant(similarity)
    match = matcher.match(sim)
    matched_cols = match.matched_column_indices()
    matched_rows = match.matched_row_indices()
    unmatched_cols = match.unmatched_column_indices()

    with self.test_session() as sess:
      res_matched_cols = sess.run(matched_cols)
      res_matched_rows = sess.run(matched_rows)
      res_unmatched_cols = sess.run(unmatched_cols)

    self.assertAllEqual(res_matched_rows, expected_matched_rows)
    self.assertAllEqual(res_matched_cols, np.arange(similarity.shape[1]))
    self.assertEmpty(res_unmatched_cols) 
Example #11
Source File: argmax_matcher_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_default_thresholds(self):

    def graph_fn(similarity_matrix):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
      match = matcher.match(similarity_matrix)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1., 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_rows = np.array([2, 0, 1, 0, 1])
    (res_matched_cols, res_unmatched_cols,
     res_match_results) = self.execute(graph_fn, [similarity])

    self.assertAllEqual(res_match_results[res_matched_cols],
                        expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], [0, 1, 2, 3, 4])
    self.assertFalse(np.all(res_unmatched_cols)) 
Example #12
Source File: matcher_builder_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def test_build_arg_max_matcher_with_non_default_parameters(self):
    matcher_text_proto = """
      argmax_matcher {
        matched_threshold: 0.7
        unmatched_threshold: 0.3
        negatives_lower_than_unmatched: false
        force_match_for_each_row: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertAlmostEqual(matcher_object._matched_threshold, 0.7)
    self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.3)
    self.assertFalse(matcher_object._negatives_lower_than_unmatched)
    self.assertTrue(matcher_object._force_match_for_each_row) 
Example #13
Source File: argmax_matcher_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_matched_threshold(self):

    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1, 2])

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #14
Source File: argmax_matcher_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_matched_and_unmatched_threshold(self):

    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.,
                                             unmatched_threshold=2.)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1])  # col 2 has too high maximum val

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #15
Source File: argmax_matcher_test.py    From vehicle_counting_tensorflow with MIT License 6 votes vote down vote up
def test_return_correct_matches_unmatched_row_while_using_force_match(self):
    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.,
                                             unmatched_threshold=2.,
                                             force_match_for_each_row=True)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [-1, 0, -2, -2, -1],
                           [3, 0, -1, 2, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 1, 3])
    expected_matched_rows = np.array([2, 1, 0])
    expected_unmatched_cols = np.array([2, 4])  # col 2 has too high max val

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #16
Source File: matcher_builder_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 6 votes vote down vote up
def test_build_arg_max_matcher_with_non_default_parameters(self):
    matcher_text_proto = """
      argmax_matcher {
        matched_threshold: 0.7
        unmatched_threshold: 0.3
        negatives_lower_than_unmatched: false
        force_match_for_each_row: true
        use_matmul_gather: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertAlmostEqual(matcher_object._matched_threshold, 0.7)
    self.assertAlmostEqual(matcher_object._unmatched_threshold, 0.3)
    self.assertFalse(matcher_object._negatives_lower_than_unmatched)
    self.assertTrue(matcher_object._force_match_for_each_row)
    self.assertTrue(matcher_object._use_matmul_gather) 
Example #17
Source File: argmax_matcher_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_default_thresholds(self):

    def graph_fn(similarity_matrix):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
      match = matcher.match(similarity_matrix)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1., 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_rows = np.array([2, 0, 1, 0, 1])
    (res_matched_cols, res_unmatched_cols,
     res_match_results) = self.execute(graph_fn, [similarity])

    self.assertAllEqual(res_match_results[res_matched_cols],
                        expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], [0, 1, 2, 3, 4])
    self.assertFalse(np.all(res_unmatched_cols)) 
Example #18
Source File: argmax_matcher_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def test_return_correct_matches_with_matched_and_unmatched_threshold(self):
    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.int32)

    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3,
                                           unmatched_threshold=2)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1])  # col 2 has too high maximum val

    sim = tf.constant(similarity)
    match = matcher.match(sim)
    matched_cols = match.matched_column_indices()
    matched_rows = match.matched_row_indices()
    unmatched_cols = match.unmatched_column_indices()

    with self.test_session() as sess:
      res_matched_cols = sess.run(matched_cols)
      res_matched_rows = sess.run(matched_rows)
      res_unmatched_cols = sess.run(unmatched_cols)

    self.assertAllEqual(res_matched_rows, expected_matched_rows)
    self.assertAllEqual(res_matched_cols, expected_matched_cols)
    self.assertAllEqual(res_unmatched_cols, expected_unmatched_cols) 
Example #19
Source File: argmax_matcher_test.py    From Person-Detection-and-Tracking with MIT License 6 votes vote down vote up
def test_return_correct_matches_with_matched_threshold(self):

    def graph_fn(similarity):
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=3.)
      match = matcher.match(similarity)
      matched_cols = match.matched_column_indicator()
      unmatched_cols = match.unmatched_column_indicator()
      match_results = match.match_results
      return (matched_cols, unmatched_cols, match_results)

    similarity = np.array([[1, 1, 1, 3, 1],
                           [2, -1, 2, 0, 4],
                           [3, 0, -1, 0, 0]], dtype=np.float32)
    expected_matched_cols = np.array([0, 3, 4])
    expected_matched_rows = np.array([2, 0, 1])
    expected_unmatched_cols = np.array([1, 2])

    (res_matched_cols, res_unmatched_cols,
     match_results) = self.execute(graph_fn, [similarity])
    self.assertAllEqual(match_results[res_matched_cols], expected_matched_rows)
    self.assertAllEqual(np.nonzero(res_matched_cols)[0], expected_matched_cols)
    self.assertAllEqual(np.nonzero(res_unmatched_cols)[0],
                        expected_unmatched_cols) 
Example #20
Source File: target_assigner_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def test_assign_agnostic(self):
    def graph_fn(anchor_means, anchor_stddevs, groundtruth_box_corners):
      similarity_calc = region_similarity_calculator.IouSimilarity()
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                             unmatched_threshold=0.5)
      box_coder = mean_stddev_box_coder.MeanStddevBoxCoder()
      target_assigner = targetassigner.TargetAssigner(
          similarity_calc, matcher, box_coder, unmatched_cls_target=None)
      anchors_boxlist = box_list.BoxList(anchor_means)
      anchors_boxlist.add_field('stddev', anchor_stddevs)
      groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners)
      result = target_assigner.assign(anchors_boxlist, groundtruth_boxlist)
      (cls_targets, cls_weights, reg_targets, reg_weights, _) = result
      return (cls_targets, cls_weights, reg_targets, reg_weights)

    anchor_means = np.array([[0.0, 0.0, 0.5, 0.5],
                             [0.5, 0.5, 1.0, 0.8],
                             [0, 0.5, .5, 1.0]], dtype=np.float32)
    anchor_stddevs = np.array(3 * [4 * [.1]], dtype=np.float32)
    groundtruth_box_corners = np.array([[0.0, 0.0, 0.5, 0.5],
                                        [0.5, 0.5, 0.9, 0.9]],
                                       dtype=np.float32)
    exp_cls_targets = [[1], [1], [0]]
    exp_cls_weights = [1, 1, 1]
    exp_reg_targets = [[0, 0, 0, 0],
                       [0, 0, -1, 1],
                       [0, 0, 0, 0]]
    exp_reg_weights = [1, 1, 0]

    (cls_targets_out, cls_weights_out, reg_targets_out,
     reg_weights_out) = self.execute(graph_fn, [anchor_means, anchor_stddevs,
                                                groundtruth_box_corners])
    self.assertAllClose(cls_targets_out, exp_cls_targets)
    self.assertAllClose(cls_weights_out, exp_cls_weights)
    self.assertAllClose(reg_targets_out, exp_reg_targets)
    self.assertAllClose(reg_weights_out, exp_reg_weights)
    self.assertEquals(cls_targets_out.dtype, np.float32)
    self.assertEquals(cls_weights_out.dtype, np.float32)
    self.assertEquals(reg_targets_out.dtype, np.float32)
    self.assertEquals(reg_weights_out.dtype, np.float32) 
Example #21
Source File: matcher_builder_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def test_build_arg_max_matcher_without_thresholds(self):
    matcher_text_proto = """
      argmax_matcher {
        ignore_thresholds: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertEqual(matcher_object._matched_threshold, None)
    self.assertEqual(matcher_object._unmatched_threshold, None)
    self.assertTrue(matcher_object._negatives_lower_than_unmatched)
    self.assertFalse(matcher_object._force_match_for_each_row) 
Example #22
Source File: target_assigner_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def _get_multi_dimensional_target_assigner(self, target_dimensions):
    similarity_calc = region_similarity_calculator.IouSimilarity()
    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                           unmatched_threshold=0.5)
    box_coder = mean_stddev_box_coder.MeanStddevBoxCoder()
    unmatched_cls_target = tf.constant(np.zeros(target_dimensions),
                                       tf.float32)
    return targetassigner.TargetAssigner(
        similarity_calc, matcher, box_coder,
        unmatched_cls_target=unmatched_cls_target) 
Example #23
Source File: target_assigner_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def _get_multi_class_target_assigner(self, num_classes):
    similarity_calc = region_similarity_calculator.IouSimilarity()
    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                           unmatched_threshold=0.5)
    box_coder = mean_stddev_box_coder.MeanStddevBoxCoder()
    unmatched_cls_target = tf.constant([1] + num_classes * [0], tf.float32)
    return targetassigner.TargetAssigner(
        similarity_calc, matcher, box_coder,
        unmatched_cls_target=unmatched_cls_target) 
Example #24
Source File: target_assigner_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def _get_agnostic_target_assigner(self):
    similarity_calc = region_similarity_calculator.IouSimilarity()
    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                           unmatched_threshold=0.5)
    box_coder = mean_stddev_box_coder.MeanStddevBoxCoder()
    return targetassigner.TargetAssigner(
        similarity_calc, matcher, box_coder,
        unmatched_cls_target=None) 
Example #25
Source File: matcher_builder_test.py    From ros_people_object_detection_tensorflow with Apache License 2.0 5 votes vote down vote up
def test_build_arg_max_matcher_without_thresholds(self):
    matcher_text_proto = """
      argmax_matcher {
        ignore_thresholds: true
      }
    """
    matcher_proto = matcher_pb2.Matcher()
    text_format.Merge(matcher_text_proto, matcher_proto)
    matcher_object = matcher_builder.build(matcher_proto)
    self.assertTrue(isinstance(matcher_object, argmax_matcher.ArgMaxMatcher))
    self.assertEqual(matcher_object._matched_threshold, None)
    self.assertEqual(matcher_object._unmatched_threshold, None)
    self.assertTrue(matcher_object._negatives_lower_than_unmatched)
    self.assertFalse(matcher_object._force_match_for_each_row) 
Example #26
Source File: argmax_matcher_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def test_invalid_arguments_no_matched_threshold(self):
    with self.assertRaises(ValueError):
      argmax_matcher.ArgMaxMatcher(matched_threshold=None,
                                   unmatched_threshold=4) 
Example #27
Source File: argmax_matcher_test.py    From DOTA_models with Apache License 2.0 5 votes vote down vote up
def test_return_correct_matches_with_empty_rows(self):

    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=None)
    sim = 0.2*tf.ones([0, 5])
    match = matcher.match(sim)
    unmatched_cols = match.unmatched_column_indices()

    with self.test_session() as sess:
      res_unmatched_cols = sess.run(unmatched_cols)
      self.assertAllEqual(res_unmatched_cols, np.arange(5)) 
Example #28
Source File: matcher_builder.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def build(matcher_config):
  """Builds a matcher object based on the matcher config.

  Args:
    matcher_config: A matcher.proto object containing the config for the desired
      Matcher.

  Returns:
    Matcher based on the config.

  Raises:
    ValueError: On empty matcher proto.
  """
  if not isinstance(matcher_config, matcher_pb2.Matcher):
    raise ValueError('matcher_config not of type matcher_pb2.Matcher.')
  if matcher_config.WhichOneof('matcher_oneof') == 'argmax_matcher':
    matcher = matcher_config.argmax_matcher
    matched_threshold = unmatched_threshold = None
    if not matcher.ignore_thresholds:
      matched_threshold = matcher.matched_threshold
      unmatched_threshold = matcher.unmatched_threshold
    return argmax_matcher.ArgMaxMatcher(
        matched_threshold=matched_threshold,
        unmatched_threshold=unmatched_threshold,
        negatives_lower_than_unmatched=matcher.negatives_lower_than_unmatched,
        force_match_for_each_row=matcher.force_match_for_each_row,
        use_matmul_gather=matcher.use_matmul_gather)
  if matcher_config.WhichOneof('matcher_oneof') == 'bipartite_matcher':
    matcher = matcher_config.bipartite_matcher
    return bipartite_matcher.GreedyBipartiteMatcher(matcher.use_matmul_gather)
  raise ValueError('Empty matcher.') 
Example #29
Source File: target_assigner_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def test_assign_agnostic(self):
    def graph_fn(anchor_means, groundtruth_box_corners):
      similarity_calc = region_similarity_calculator.IouSimilarity()
      matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                             unmatched_threshold=0.5)
      box_coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
      target_assigner = targetassigner.TargetAssigner(
          similarity_calc, matcher, box_coder)
      anchors_boxlist = box_list.BoxList(anchor_means)
      groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners)
      result = target_assigner.assign(
          anchors_boxlist, groundtruth_boxlist, unmatched_class_label=None)
      (cls_targets, cls_weights, reg_targets, reg_weights, _) = result
      return (cls_targets, cls_weights, reg_targets, reg_weights)

    anchor_means = np.array([[0.0, 0.0, 0.5, 0.5],
                             [0.5, 0.5, 1.0, 0.8],
                             [0, 0.5, .5, 1.0]], dtype=np.float32)
    groundtruth_box_corners = np.array([[0.0, 0.0, 0.5, 0.5],
                                        [0.5, 0.5, 0.9, 0.9]],
                                       dtype=np.float32)
    exp_cls_targets = [[1], [1], [0]]
    exp_cls_weights = [[1], [1], [1]]
    exp_reg_targets = [[0, 0, 0, 0],
                       [0, 0, -1, 1],
                       [0, 0, 0, 0]]
    exp_reg_weights = [1, 1, 0]

    (cls_targets_out,
     cls_weights_out, reg_targets_out, reg_weights_out) = self.execute(
         graph_fn, [anchor_means, groundtruth_box_corners])
    self.assertAllClose(cls_targets_out, exp_cls_targets)
    self.assertAllClose(cls_weights_out, exp_cls_weights)
    self.assertAllClose(reg_targets_out, exp_reg_targets)
    self.assertAllClose(reg_weights_out, exp_reg_weights)
    self.assertEquals(cls_targets_out.dtype, np.float32)
    self.assertEquals(cls_weights_out.dtype, np.float32)
    self.assertEquals(reg_targets_out.dtype, np.float32)
    self.assertEquals(reg_weights_out.dtype, np.float32) 
Example #30
Source File: target_assigner_test.py    From vehicle_counting_tensorflow with MIT License 5 votes vote down vote up
def _get_target_assigner(self):
    similarity_calc = region_similarity_calculator.IouSimilarity()
    matcher = argmax_matcher.ArgMaxMatcher(matched_threshold=0.5,
                                           unmatched_threshold=0.5)
    box_coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
    return targetassigner.TargetAssigner(similarity_calc, matcher, box_coder)