Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 1 | /* |
Richard Burton | f32a86a | 2022-11-15 11:46:11 +0000 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [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 VWW_PROCESSING_HPP |
| 18 | #define VWW_PROCESSING_HPP |
| 19 | |
| 20 | #include "BaseProcessing.hpp" |
| 21 | #include "Model.hpp" |
| 22 | #include "Classifier.hpp" |
| 23 | |
| 24 | namespace arm { |
| 25 | namespace app { |
| 26 | |
| 27 | /** |
| 28 | * @brief Pre-processing class for Visual Wake Word use case. |
| 29 | * Implements methods declared by BasePreProcess and anything else needed |
| 30 | * to populate input tensors ready for inference. |
| 31 | */ |
| 32 | class VisualWakeWordPreProcess : public BasePreProcess { |
| 33 | |
| 34 | public: |
| 35 | /** |
| 36 | * @brief Constructor |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 37 | * @param[in] inputTensor Pointer to the TFLite Micro input Tensor. |
Richard Burton | fcca863 | 2022-05-05 17:23:43 +0100 | [diff] [blame] | 38 | * @param[in] rgb2Gray Convert image from 3 channel RGB to 1 channel grayscale. |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 39 | **/ |
Richard Burton | fcca863 | 2022-05-05 17:23:43 +0100 | [diff] [blame] | 40 | explicit VisualWakeWordPreProcess(TfLiteTensor* inputTensor, bool rgb2Gray=true); |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * @brief Should perform pre-processing of 'raw' input image data and load it into |
| 44 | * TFLite Micro input tensors ready for inference |
| 45 | * @param[in] input Pointer to the data that pre-processing will work on. |
| 46 | * @param[in] inputSize Size of the input data. |
| 47 | * @return true if successful, false otherwise. |
| 48 | **/ |
| 49 | bool DoPreProcess(const void* input, size_t inputSize) override; |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | TfLiteTensor* m_inputTensor; |
Richard Burton | fcca863 | 2022-05-05 17:23:43 +0100 | [diff] [blame] | 53 | bool m_rgb2Gray; |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * @brief Post-processing class for Visual Wake Word use case. |
| 58 | * Implements methods declared by BasePostProcess and anything else needed |
| 59 | * to populate result vector. |
| 60 | */ |
| 61 | class VisualWakeWordPostProcess : public BasePostProcess { |
| 62 | |
| 63 | private: |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 64 | TfLiteTensor* m_outputTensor; |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 65 | Classifier& m_vwwClassifier; |
| 66 | const std::vector<std::string>& m_labels; |
| 67 | std::vector<ClassificationResult>& m_results; |
| 68 | |
| 69 | public: |
| 70 | /** |
| 71 | * @brief Constructor |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 72 | * @param[in] outputTensor Pointer to the TFLite Micro output Tensor. |
| 73 | * @param[in] classifier Classifier object used to get top N results from classification. |
| 74 | * @param[in] model Pointer to the VWW classification Model object. |
| 75 | * @param[in] labels Vector of string labels to identify each output of the model. |
| 76 | * @param[out] results Vector of classification results to store decoded outputs. |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 77 | **/ |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 78 | VisualWakeWordPostProcess(TfLiteTensor* outputTensor, Classifier& classifier, |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 79 | const std::vector<std::string>& labels, |
| 80 | std::vector<ClassificationResult>& results); |
| 81 | |
| 82 | /** |
Richard Burton | b40ecf8 | 2022-04-22 16:14:57 +0100 | [diff] [blame] | 83 | * @brief Should perform post-processing of the result of inference then |
| 84 | * populate classification result data for any later use. |
| 85 | * @return true if successful, false otherwise. |
Richard Burton | c20be97 | 2022-04-19 17:01:08 +0100 | [diff] [blame] | 86 | **/ |
| 87 | bool DoPostProcess() override; |
| 88 | }; |
| 89 | |
| 90 | } /* namespace app */ |
| 91 | } /* namespace arm */ |
| 92 | |
| 93 | #endif /* VWW_PROCESSING_HPP */ |