def test_temperature_scaling(self):
    'Tests that calibration produces correct temperature scaling values.'
    calibration_config = calibration_pb2.CalibrationConfig()
    calibration_config.temperature_scaling_calibration.scaler = 2.0

    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.3, 0.35, 0.4], [0.45, 0.5, 0.5]]])
Tests that calibration produces correct temperature scaling values.
def test_temperature_scaling(self):
    
    calibration_config = calibration_pb2.CalibrationConfig()
    calibration_config.temperature_scaling_calibration.scaler = 2.0

    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.3, 0.35, 0.4], [0.45, 0.5, 0.5]]])