#include <math.h>
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <initializer_list>
#include <numeric>
#include <vector>
#include "flatbuffers/flexbuffers.h"
#include "tensorflow/lite/core/c/common.h"
#include "tensorflow/lite/kernels/internal/compatibility.h"
#include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h"
#include "tensorflow/lite/kernels/internal/reference/reference_ops.h"
#include "tensorflow/lite/kernels/internal/tensor.h"
#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
#include "tensorflow/lite/kernels/kernel_util.h"
namespace tflite {
namespace ops {
namespace custom {
namespace detection_postprocess {
constexpr int kInputTensorBoxEncodings = …;
constexpr int kInputTensorClassPredictions = …;
constexpr int kInputTensorAnchors = …;
constexpr int kOutputTensorDetectionBoxes = …;
constexpr int kOutputTensorDetectionClasses = …;
constexpr int kOutputTensorDetectionScores = …;
constexpr int kOutputTensorNumDetections = …;
constexpr int kNumCoordBox = …;
constexpr int kBatchSize = …;
constexpr int kNumDetectionsPerClass = …;
struct BoxCornerEncoding { … };
struct CenterSizeEncoding { … };
static_assert …;
static_assert …;
struct OpData { … };
void* Init(TfLiteContext* context, const char* buffer, size_t length) { … }
void Free(TfLiteContext* context, void* buffer) { … }
TfLiteStatus SetTensorSizes(TfLiteContext* context, TfLiteTensor* tensor,
std::initializer_list<int> values) { … }
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { … }
class Dequantizer { … };
void DequantizeBoxEncodings(const TfLiteTensor* input_box_encodings, int idx,
float quant_zero_point, float quant_scale,
int length_box_encoding,
CenterSizeEncoding* box_centersize) { … }
template <class T>
T ReInterpretTensor(const TfLiteTensor* tensor) { … }
template <class T>
T ReInterpretTensor(TfLiteTensor* tensor) { … }
TfLiteStatus DecodeCenterSizeBoxes(TfLiteContext* context, TfLiteNode* node,
OpData* op_data) { … }
void DecreasingPartialArgSort(const float* values, int num_values,
int num_to_sort, int* indices) { … }
void DecreasingArgSort(const float* values, int num_values, int* indices) { … }
void SelectDetectionsAboveScoreThreshold(const std::vector<float>& values,
const float threshold,
std::vector<float>* keep_values,
std::vector<int>* keep_indices) { … }
bool ValidateBoxes(const TfLiteTensor* decoded_boxes, const int num_boxes) { … }
float ComputeIntersectionOverUnion(const TfLiteTensor* decoded_boxes,
const int i, const int j) { … }
TfLiteStatus NonMaxSuppressionSingleClassHelper(
TfLiteContext* context, TfLiteNode* node, OpData* op_data,
const std::vector<float>& scores, int max_detections,
std::vector<int>* selected) { … }
struct BoxInfo { … };
struct NMSTaskParam { … };
void InplaceMergeBoxInfo(std::vector<BoxInfo>& boxes, int mid_index,
int end_index) { … }
TfLiteStatus ComputeNMSResult(const NMSTaskParam& nms_task_param, int col_begin,
int col_end, int& sorted_indices_size,
std::vector<BoxInfo>& resulted_sorted_box_info) { … }
struct NonMaxSuppressionWorkerTask : cpu_backend_threadpool::Task { … };
TfLiteStatus NonMaxSuppressionMultiClassRegularHelper(TfLiteContext* context,
TfLiteNode* node,
OpData* op_data,
const float* scores) { … }
TfLiteStatus NonMaxSuppressionMultiClassFastHelper(TfLiteContext* context,
TfLiteNode* node,
OpData* op_data,
const float* scores) { … }
void DequantizeClassPredictions(const TfLiteTensor* input_class_predictions,
const int num_boxes,
const int num_classes_with_background,
TfLiteTensor* scores) { … }
TfLiteStatus NonMaxSuppressionMultiClass(TfLiteContext* context,
TfLiteNode* node, OpData* op_data) { … }
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { … }
}
TfLiteRegistration* Register_DETECTION_POSTPROCESS() { … }
TfLiteRegistration* Register_TFLITE_DETECTION_POST_PROCESS() { … }
}
}
}