blob: e33e3c1df3dc6522d2edd3c918d6c15f0e750231 [file] [log] [blame]
Richard Burton11b75cc2022-04-07 18:00:55 +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#include "ImgClassProcessing.hpp"
18#include "ImageUtils.hpp"
19#include "log_macros.h"
20
21namespace arm {
22namespace app {
23
24 ImgClassPreProcess::ImgClassPreProcess(Model* model)
25 {
26 this->m_model = model;
27 }
28
29 bool ImgClassPreProcess::DoPreProcess(const void* data, size_t inputSize)
30 {
31 if (data == nullptr) {
32 printf_err("Data pointer is null");
33 }
34
35 auto input = static_cast<const uint8_t*>(data);
36 TfLiteTensor* inputTensor = this->m_model->GetInputTensor(0);
37
38 memcpy(inputTensor->data.data, input, inputSize);
39 debug("Input tensor populated \n");
40
41 if (this->m_model->IsDataSigned()) {
42 image::ConvertImgToInt8(inputTensor->data.data, inputTensor->bytes);
43 }
44
45 return true;
46 }
47
48 ImgClassPostProcess::ImgClassPostProcess(Classifier& classifier, Model* model,
49 const std::vector<std::string>& labels,
50 std::vector<ClassificationResult>& results)
51 :m_imgClassifier{classifier},
52 m_labels{labels},
53 m_results{results}
54 {
55 this->m_model = model;
56 }
57
58 bool ImgClassPostProcess::DoPostProcess()
59 {
60 return this->m_imgClassifier.GetClassificationResults(
61 this->m_model->GetOutputTensor(0), this->m_results,
62 this->m_labels, 5, false);
63 }
64
65} /* namespace app */
66} /* namespace arm */