blob: 3a42ddededace3429493f89a7c305404547f7f7d [file] [log] [blame]
Éanna Ó Catháin8f958872021-09-15 09:32:30 +01001/*
2 * Copyright (c) 2021 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
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010018#include "hal.h"
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010019#include "ImageUtils.hpp"
20#include "TestData_vww.hpp"
21#include "VisualWakeWordModel.hpp"
22#include "TensorFlowLiteMicro.hpp"
23
Isabella Gottardi5cbcd9e2021-10-15 10:17:33 +010024#include <catch.hpp>
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010025
26bool RunInference(arm::app::Model& model, const int8_t* imageData)
27{
28 TfLiteTensor* inputTensor = model.GetInputTensor(0);
29 REQUIRE(inputTensor);
30
Isabella Gottardi5cbcd9e2021-10-15 10:17:33 +010031 const size_t copySz = inputTensor->bytes < IFM_DATA_SIZE ?
32 inputTensor->bytes :
33 IFM_DATA_SIZE;
34
35 memcpy(inputTensor->data.data, imageData, copySz);
36
37 if(model.IsDataSigned()){
38 convertImgIoInt8(inputTensor->data.data, copySz);
39 }
40
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010041 return model.RunInference();
42}
43
44template<typename T>
45void TestInference(int imageIdx,arm::app::Model& model) {
46
47 auto image = test::get_ifm_data_array(imageIdx);
48 auto goldenFV = test::get_ofm_data_array(imageIdx);
49
50 REQUIRE(RunInference(model, image));
51
52 TfLiteTensor* outputTensor = model.GetOutputTensor(0);
53
54 REQUIRE(outputTensor);
55 REQUIRE(outputTensor->bytes == OFM_DATA_SIZE);
56 auto tensorData = tflite::GetTensorData<T>(outputTensor);
57 REQUIRE(tensorData);
58
59 for (size_t i = 0; i < outputTensor->bytes; i++) {
60 auto testVal = static_cast<int>(tensorData[i]);
61 auto goldenVal = static_cast<int>(goldenFV[i]);
62 CHECK(testVal == goldenVal);
63 }
64}