alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
Richard Burton | f32a86a | 2022-11-15 11:46:11 +0000 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 3 | * 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 | |
| 22 | namespace arm { |
| 23 | namespace 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 Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 35 | * @param[in] use_softmax Whether softmax scaling should be applied to model output. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 36 | * @return true if successful, false otherwise. |
| 37 | **/ |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 38 | 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; |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 42 | |
| 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> |
alexander | c350cdc | 2021-04-29 20:36:09 +0100 | [diff] [blame] | 55 | bool GetTopResults(TfLiteTensor* tensor, |
| 56 | std::vector<ClassificationResult>& vecResults, |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 57 | const std::vector<std::string>& labels, double scale, double zeroPoint); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } /* namespace app */ |
| 61 | } /* namespace arm */ |
| 62 | |
| 63 | #endif /* ASR_CLASSIFIER_HPP */ |