def test_build_softmax_score_converter(self):
     post_processing_text_proto = """
   score_converter: SOFTMAX
 """
     post_processing_config = post_processing_pb2.PostProcessing()
     text_format.Merge(post_processing_text_proto, post_processing_config)
     _, score_converter = post_processing_builder.build(
         post_processing_config)
     self.assertEqual(score_converter.__name__, 'softmax_with_logit_scale')
    def test_build_identity_score_converter(self):
        post_processing_text_proto = """
      score_converter: IDENTITY
    """
        post_processing_config = post_processing_pb2.PostProcessing()
        text_format.Merge(post_processing_text_proto, post_processing_config)
        _, score_converter = post_processing_builder.build(
            post_processing_config)
        self.assertEqual(score_converter.__name__, 'identity_with_logit_scale')

        inputs = tf.constant([1, 1], tf.float32)
        outputs = score_converter(inputs)
        with self.test_session() as sess:
            converted_scores = sess.run(outputs)
            expected_converted_scores = sess.run(inputs)
            self.assertAllClose(converted_scores, expected_converted_scores)
 def test_build_non_max_suppressor_with_correct_parameters(self):
     post_processing_text_proto = """
   batch_non_max_suppression {
     score_threshold: 0.7
     iou_threshold: 0.6
     max_detections_per_class: 100
     max_total_detections: 300
   }
 """
     post_processing_config = post_processing_pb2.PostProcessing()
     text_format.Merge(post_processing_text_proto, post_processing_config)
     non_max_suppressor, _ = post_processing_builder.build(
         post_processing_config)
     self.assertEqual(non_max_suppressor.keywords['max_size_per_class'],
                      100)
     self.assertEqual(non_max_suppressor.keywords['max_total_size'], 300)
     self.assertAlmostEqual(non_max_suppressor.keywords['score_thresh'],
                            0.7)
     self.assertAlmostEqual(non_max_suppressor.keywords['iou_thresh'], 0.6)