def test_class_agnostic_function_approximation(self):
    'Tests that calibration produces correct class-agnostic values.'
    class_agnostic_x = np.asarray([0.0, 0.5, 1.0])
    class_agnostic_y = np.asarray([0.0, 0.25, 0.75])
    calibration_config = calibration_pb2.CalibrationConfig()
    self._add_function_approximation_to_calibration_proto(calibration_config, class_agnostic_x, class_agnostic_y, class_id=None)

    def graph_fn():
        calibration_fn = calibration_builder.build(calibration_config)
        class_predictions_with_background = tf.constant([[[0.1, 0.2, 0.3], [0.4, 0.5, 0.0]], [[0.6, 0.7, 0.8], [0.9, 1.0, 1.0]]], dtype=tf.float32)
        calibrated_scores = calibration_fn(class_predictions_with_background)
        return calibrated_scores
    calibrated_scores_np = self.execute(graph_fn, [])
    self.assertAllClose(calibrated_scores_np, [[[0.05, 0.1, 0.15], [0.2, 0.25, 0.0]], [[0.35, 0.45, 0.55], [0.65, 0.75, 0.75]]])
Tests that calibration produces correct class-agnostic values.
def test_class_agnostic_function_approximation(self):
    
    class_agnostic_x = np.asarray([0.0, 0.5, 1.0])
    class_agnostic_y = np.asarray([0.0, 0.25, 0.75])
    calibration_config = calibration_pb2.CalibrationConfig()
    self._add_function_approximation_to_calibration_proto(calibration_config, class_agnostic_x, class_agnostic_y, class_id=None)

    def graph_fn():
        calibration_fn = calibration_builder.build(calibration_config)
        class_predictions_with_background = tf.constant([[[0.1, 0.2, 0.3], [0.4, 0.5, 0.0]], [[0.6, 0.7, 0.8], [0.9, 1.0, 1.0]]], dtype=tf.float32)
        calibrated_scores = calibration_fn(class_predictions_with_background)
        return calibrated_scores
    calibrated_scores_np = self.execute(graph_fn, [])
    self.assertAllClose(calibrated_scores_np, [[[0.05, 0.1, 0.15], [0.2, 0.25, 0.0]], [[0.35, 0.45, 0.55], [0.65, 0.75, 0.75]]])