blob: bef161fb7872b24b9498101581c133babdefa5dd [file] [log] [blame]
Richard Burtonc20be972022-04-19 17:01:08 +01001/*
2 * Copyright (c) 2022 Arm Limited. All rights reserved.
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
24namespace arm {
25namespace 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 Burtonb40ecf82022-04-22 16:14:57 +010037 * @param[in] inputTensor Pointer to the TFLite Micro input Tensor.
Richard Burtonc20be972022-04-19 17:01:08 +010038 **/
Richard Burtonb40ecf82022-04-22 16:14:57 +010039 explicit VisualWakeWordPreProcess(TfLiteTensor* inputTensor);
Richard Burtonc20be972022-04-19 17:01:08 +010040
41 /**
42 * @brief Should perform pre-processing of 'raw' input image data and load it into
43 * TFLite Micro input tensors ready for inference
44 * @param[in] input Pointer to the data that pre-processing will work on.
45 * @param[in] inputSize Size of the input data.
46 * @return true if successful, false otherwise.
47 **/
48 bool DoPreProcess(const void* input, size_t inputSize) override;
Richard Burtonb40ecf82022-04-22 16:14:57 +010049
50 private:
51 TfLiteTensor* m_inputTensor;
Richard Burtonc20be972022-04-19 17:01:08 +010052 };
53
54 /**
55 * @brief Post-processing class for Visual Wake Word use case.
56 * Implements methods declared by BasePostProcess and anything else needed
57 * to populate result vector.
58 */
59 class VisualWakeWordPostProcess : public BasePostProcess {
60
61 private:
Richard Burtonb40ecf82022-04-22 16:14:57 +010062 TfLiteTensor* m_outputTensor;
Richard Burtonc20be972022-04-19 17:01:08 +010063 Classifier& m_vwwClassifier;
64 const std::vector<std::string>& m_labels;
65 std::vector<ClassificationResult>& m_results;
66
67 public:
68 /**
69 * @brief Constructor
Richard Burtonb40ecf82022-04-22 16:14:57 +010070 * @param[in] outputTensor Pointer to the TFLite Micro output Tensor.
71 * @param[in] classifier Classifier object used to get top N results from classification.
72 * @param[in] model Pointer to the VWW classification Model object.
73 * @param[in] labels Vector of string labels to identify each output of the model.
74 * @param[out] results Vector of classification results to store decoded outputs.
Richard Burtonc20be972022-04-19 17:01:08 +010075 **/
Richard Burtonb40ecf82022-04-22 16:14:57 +010076 VisualWakeWordPostProcess(TfLiteTensor* outputTensor, Classifier& classifier,
Richard Burtonc20be972022-04-19 17:01:08 +010077 const std::vector<std::string>& labels,
78 std::vector<ClassificationResult>& results);
79
80 /**
Richard Burtonb40ecf82022-04-22 16:14:57 +010081 * @brief Should perform post-processing of the result of inference then
82 * populate classification result data for any later use.
83 * @return true if successful, false otherwise.
Richard Burtonc20be972022-04-19 17:01:08 +010084 **/
85 bool DoPostProcess() override;
86 };
87
88} /* namespace app */
89} /* namespace arm */
90
91#endif /* VWW_PROCESSING_HPP */