blob: 805f4c5fed7deb3d682ce2f627ab5b18123aef17 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
alexander3c798932021-03-26 21:42:19 +00003 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef ASR_CLASSIFIER_HPP
18#define ASR_CLASSIFIER_HPP
19
20#include "Classifier.hpp"
21
22namespace arm {
23namespace app {
24
25 class AsrClassifier : public Classifier {
26 public:
27 /**
28 * @brief Gets the top N classification results from the
29 * output vector.
30 * @param[in] outputTensor Inference output tensor from an NN model.
31 * @param[out] vecResults A vector of classification results
32 * populated by this function.
33 * @param[in] labels Labels vector to match classified classes
34 * @param[in] topNCount Number of top classifications to pick.
Kshitij Sisodia76a15802021-12-24 11:05:11 +000035 * @param[in] use_softmax Whether softmax scaling should be applied to model output.
alexander3c798932021-03-26 21:42:19 +000036 * @return true if successful, false otherwise.
37 **/
Richard Burtonb40ecf82022-04-22 16:14:57 +010038 bool GetClassificationResults(TfLiteTensor* outputTensor,
39 std::vector<ClassificationResult>& vecResults,
40 const std::vector<std::string>& labels,
41 uint32_t topNCount, bool use_softmax = false) override;
alexander3c798932021-03-26 21:42:19 +000042
43 private:
44 /**
45 * @brief Utility function that gets the top 1 classification results from the
46 * output tensor (vector of vector).
47 * @param[in] tensor Inference output tensor from an NN model.
48 * @param[out] vecResults Vector of classification results populated by this function.
49 * @param[in] labels Labels vector to match classified classes.
50 * @param[in] scale Quantization scale.
51 * @param[in] zeroPoint Quantization zero point.
52 * @return true if successful, false otherwise.
53 **/
54 template<typename T>
alexanderc350cdc2021-04-29 20:36:09 +010055 bool GetTopResults(TfLiteTensor* tensor,
56 std::vector<ClassificationResult>& vecResults,
Richard Burtonb40ecf82022-04-22 16:14:57 +010057 const std::vector<std::string>& labels, double scale, double zeroPoint);
alexander3c798932021-03-26 21:42:19 +000058 };
59
60} /* namespace app */
61} /* namespace arm */
62
63#endif /* ASR_CLASSIFIER_HPP */