Ejemplo n.º 1
0
 def testGetCorrectMatchedRowIndices(self):
     match_results = tf.constant([3, 1, -1, 0, -1, 5, -2])
     match = matcher.Match(match_results)
     expected_row_indices = [3, 1, 0, 5]
     matched_row_indices = match.matched_row_indices()
     self.assertEquals(matched_row_indices.dtype, tf.int32)
     with self.test_session() as sess:
         matched_row_inds = sess.run(matched_row_indices)
         self.assertAllEqual(matched_row_inds, expected_row_indices)
Ejemplo n.º 2
0
 def test_get_correct_ignored_column_indices(self):
     match_results = tf.constant([3, 1, -1, 0, -1, 5, -2])
     match = matcher.Match(match_results)
     expected_column_indices = [6]
     ignored_column_indices = match.ignored_column_indices()
     self.assertEquals(ignored_column_indices.dtype, tf.int32)
     with self.test_session() as sess:
         ignored_column_indices = sess.run(ignored_column_indices)
         self.assertAllEqual(ignored_column_indices,
                             expected_column_indices)
Ejemplo n.º 3
0
 def testGetCorrectUnmatchedColumnIndices(self):
     match_results = tf.constant([3, 1, -1, 0, -1, 5, -2])
     match = matcher.Match(match_results)
     expected_column_indices = [2, 4]
     unmatched_column_indices = match.unmatched_column_indices()
     self.assertEquals(unmatched_column_indices.dtype, tf.int32)
     with self.test_session() as sess:
         unmatched_column_indices = sess.run(unmatched_column_indices)
         self.assertAllEqual(unmatched_column_indices,
                             expected_column_indices)
Ejemplo n.º 4
0
 def test_get_correct_matched_column_indicator(self):
     match_results = tf.constant([3, 1, -1, 0, -1, 5, -2])
     match = matcher.Match(match_results)
     expected_column_indicator = [
         True, True, False, True, False, True, False
     ]
     matched_column_indicator = match.matched_column_indicator()
     self.assertEquals(matched_column_indicator.dtype, tf.bool)
     with self.test_session() as sess:
         matched_column_indicator = sess.run(matched_column_indicator)
         self.assertAllEqual(matched_column_indicator,
                             expected_column_indicator)
Ejemplo n.º 5
0
  def testEnforceNegativesPerPositiveRatioWithMinNegativesPerImage(self):
    location_losses = tf.constant([[100, 90, 80, 0, 1, 2,
                                    3, 10, 20, 100, 20, 3]], tf.float32)
    cls_losses = tf.constant([[0, 0, 100, 0, 90, 70,
                               0, 60, 0, 17, 13, 0]], tf.float32)
    box_corners = tf.constant([[0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 0.5, 0.1],
                               [0.0, 0.0, 0.6, 0.1],
                               [0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 0.8, 0.1],
                               [0.0, 0.0, 0.2, 0.1],
                               [0.0, 0.0, 1.0, 0.1],
                               [0.0, 0.0, 1.1, 0.1],
                               [0.0, 0.0, 0.2, 0.1]], tf.float32)
    match_results = tf.constant([-1] * 12)
    match_list = [matcher.Match(match_results)]
    decoded_boxlist_list = []
    decoded_boxlist_list.append(box_list.BoxList(box_corners))

    min_negatives_per_image_list = [0, 1, 2, 4, 5, 6]
    exp_loc_loss_list = [0,
                         80,
                         80 + 1,
                         80 + 1 + 2 + 10,
                         80 + 1 + 2 + 10 + 100,
                         80 + 1 + 2 + 10 + 100 + 20]
    exp_cls_loss_list = [0,
                         100,
                         100 + 90,
                         100 + 90 + 70 + 60,
                         100 + 90 + 70 + 60 + 17,
                         100 + 90 + 70 + 60 + 17 + 13]

    for min_negatives_per_image, exp_loc_loss, exp_cls_loss in zip(
        min_negatives_per_image_list, exp_loc_loss_list, exp_cls_loss_list):
      loss_op = losses.HardExampleMiner(
          num_hard_examples=None, iou_threshold=0.9999, loss_type='cls',
          cls_loss_weight=1, loc_loss_weight=1,
          max_negatives_per_positive=3,
          min_negatives_per_image=min_negatives_per_image)
      (loc_loss, cls_loss) = loss_op(location_losses, cls_losses,
                                     decoded_boxlist_list, match_list)
      with self.test_session() as sess:
        loc_loss_output = sess.run(loc_loss)
        self.assertAllClose(loc_loss_output, exp_loc_loss)
        cls_loss_output = sess.run(cls_loss)
        self.assertAllClose(cls_loss_output, exp_cls_loss)
Ejemplo n.º 6
0
 def test_all_columns_accounted_for(self):
     # Note: deliberately setting to small number so not always
     # all possibilities appear (matched, unmatched, ignored)
     num_matches = 10
     match_results = tf.random_uniform([num_matches],
                                       minval=-2,
                                       maxval=5,
                                       dtype=tf.int32)
     match = matcher.Match(match_results)
     matched_column_indices = match.matched_column_indices()
     unmatched_column_indices = match.unmatched_column_indices()
     ignored_column_indices = match.ignored_column_indices()
     with self.test_session() as sess:
         matched, unmatched, ignored = sess.run([
             matched_column_indices, unmatched_column_indices,
             ignored_column_indices
         ])
         all_indices = np.hstack((matched, unmatched, ignored))
         all_indices_sorted = np.sort(all_indices)
         self.assertAllEqual(all_indices_sorted,
                             np.arange(num_matches, dtype=np.int32))
Ejemplo n.º 7
0
 def test_get_correct_counts(self):
     match_results = tf.constant([3, 1, -1, 0, -1, 5, -2])
     match = matcher.Match(match_results)
     exp_num_matched_columns = 4
     exp_num_unmatched_columns = 2
     exp_num_ignored_columns = 1
     num_matched_columns = match.num_matched_columns()
     num_unmatched_columns = match.num_unmatched_columns()
     num_ignored_columns = match.num_ignored_columns()
     self.assertEquals(num_matched_columns.dtype, tf.int32)
     self.assertEquals(num_unmatched_columns.dtype, tf.int32)
     self.assertEquals(num_ignored_columns.dtype, tf.int32)
     with self.test_session() as sess:
         (num_matched_columns_out, num_unmatched_columns_out,
          num_ignored_columns_out) = sess.run([
              num_matched_columns, num_unmatched_columns,
              num_ignored_columns
          ])
         self.assertAllEqual(num_matched_columns_out,
                             exp_num_matched_columns)
         self.assertAllEqual(num_unmatched_columns_out,
                             exp_num_unmatched_columns)
         self.assertAllEqual(num_ignored_columns_out,
                             exp_num_ignored_columns)