chromium/third_party/tflite_support/src/tensorflow_lite_support/cc/task/vision/utils/score_calibration.cc

/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow_lite_support/cc/task/vision/utils/score_calibration.h"

#include <algorithm>
#include <cmath>
#include <memory>
#include <utility>
#include <vector>

#include "absl/status/status.h"  // from @com_google_absl
#include "absl/strings/numbers.h"  // from @com_google_absl
#include "absl/strings/str_format.h"  // from @com_google_absl
#include "absl/strings/str_split.h"  // from @com_google_absl
#include "absl/strings/string_view.h"  // from @com_google_absl
#include "absl/types/optional.h"  // from @com_google_absl
#include "tensorflow_lite_support/cc/common.h"
#include "tensorflow_lite_support/cc/port/status_macros.h"

namespace tflite {
namespace task {
namespace vision {
namespace {

StatusCode;
CreateStatusWithPayload;
StatusOr;
TfLiteSupportStatus;

// Used to prevent log(<=0.0) in ClampedLog() calls.
constexpr float kLogScoreMinimum =;

// Returns the following, depending on x:
//   x => threshold: log(x)
//   x < threshold: 2 * log(thresh) - log(2 * thresh - x)
// This form (a) is anti-symmetric about the threshold and (b) has continuous
// value and first derivative. This is done to prevent taking the log of values
// close to 0 which can lead to floating point errors and is better than simple
// clamping since it preserves order for scores less than the threshold.
float ClampedLog(float x, float threshold) {}

// Applies the specified score transformation to the provided score.
// Currently supports the following,
//   IDENTITY         : f(x) = x
//   LOG              : f(x) = log(x)
//   INVERSE_LOGISTIC : f(x) = log(x) - log(1-x)
float ApplyScoreTransformation(float score, const ScoreTransformation& type) {}

// Builds a single Sigmoid from the label name and associated CSV file line.
StatusOr<Sigmoid> SigmoidFromLabelAndLine(absl::string_view label,
                                          absl::string_view line) {}

// Converts a tflite::ScoreTransformationType to its
// tflite::task::vision::ScoreTransformation equivalent.
ScoreTransformation ConvertScoreTransformationType(
    tflite::ScoreTransformationType type) {}

}  // namespace

std::ostream& operator<<(std::ostream& os, const Sigmoid& s) {}

ScoreCalibration::ScoreCalibration() {}
ScoreCalibration::~ScoreCalibration() {}

absl::Status ScoreCalibration::InitializeFromParameters(
    const SigmoidCalibrationParameters& params) {}

float ScoreCalibration::ComputeCalibratedScore(const std::string& label,
                                               float uncalibrated_score) const {}

absl::optional<Sigmoid> ScoreCalibration::FindSigmoidParameters(
    const std::string& label) const {}

StatusOr<SigmoidCalibrationParameters> BuildSigmoidCalibrationParams(
    const tflite::ScoreCalibrationOptions& score_calibration_options,
    absl::string_view score_calibration_file,
    const std::vector<LabelMapItem>& label_map_items) {}

}  // namespace vision
}  // namespace task
}  // namespace tflite