diff options
Diffstat (limited to 'tests/use_case/noise_reduction')
-rw-r--r-- | tests/use_case/noise_reduction/InferenceTestRNNoise.cc | 54 | ||||
-rw-r--r-- | tests/use_case/noise_reduction/RNNNoiseUCTests.cc | 85 |
2 files changed, 71 insertions, 68 deletions
diff --git a/tests/use_case/noise_reduction/InferenceTestRNNoise.cc b/tests/use_case/noise_reduction/InferenceTestRNNoise.cc index 3cdaee1..17ce9ac 100644 --- a/tests/use_case/noise_reduction/InferenceTestRNNoise.cc +++ b/tests/use_case/noise_reduction/InferenceTestRNNoise.cc @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com> - * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates + * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "TensorFlowLiteMicro.hpp" +#include "BufAttributes.hpp" #include "RNNoiseModel.hpp" +#include "TensorFlowLiteMicro.hpp" #include "TestData_noise_reduction.hpp" -#include "BufAttributes.hpp" #include <catch.hpp> #include <random> @@ -50,15 +50,13 @@ namespace noise_reduction { { std::random_device rndDevice; std::mt19937 mersenneGen{rndDevice()}; - std::uniform_int_distribution<short> dist {-128, 127}; + std::uniform_int_distribution<short> dist{-128, 127}; - auto gen = [&dist, &mersenneGen](){ - return dist(mersenneGen); - }; + auto gen = [&dist, &mersenneGen]() { return dist(mersenneGen); }; std::vector<std::vector<int8_t>> randomInput{NUMBER_OF_IFM_FILES}; for (size_t i = 0; i < model.GetNumInputs(); ++i) { - TfLiteTensor *inputTensor = model.GetInputTensor(i); + TfLiteTensor* inputTensor = model.GetInputTensor(i); REQUIRE(inputTensor); randomInput[i].resize(inputTensor->bytes); std::generate(std::begin(randomInput[i]), std::end(randomInput[i]), gen); @@ -82,8 +80,10 @@ namespace noise_reduction { REQUIRE(RunInferenceRandom(model)); } - template<typename T> - void TestInference(const std::vector<std::vector<T>> input_goldenFV, const std::vector<std::vector<T>> output_goldenFV, arm::app::Model& model) + template <typename T> + void TestInference(const std::vector<std::vector<T>> input_goldenFV, + const std::vector<std::vector<T>> output_goldenFV, + arm::app::Model& model) { for (size_t i = 0; i < model.GetNumInputs(); ++i) { TfLiteTensor* inputTensor = model.GetInputTensor(i); @@ -93,41 +93,37 @@ namespace noise_reduction { REQUIRE(RunInference(model, input_goldenFV)); for (size_t i = 0; i < model.GetNumOutputs(); ++i) { - TfLiteTensor *outputTensor = model.GetOutputTensor(i); + TfLiteTensor* outputTensor = model.GetOutputTensor(i); REQUIRE(outputTensor); auto tensorData = tflite::GetTensorData<T>(outputTensor); REQUIRE(tensorData); for (size_t j = 0; j < outputTensor->bytes; j++) { - REQUIRE(static_cast<int>(tensorData[j]) == static_cast<int>((output_goldenFV[i][j]))); + REQUIRE(static_cast<int>(tensorData[j]) == + static_cast<int>((output_goldenFV[i][j]))); } } } TEST_CASE("Running inference with Tflu and RNNoise Int8", "[RNNoise]") { - std::vector<std::vector<int8_t>> goldenInputFV {NUMBER_OF_IFM_FILES}; - std::vector<std::vector<int8_t>> goldenOutputFV {NUMBER_OF_OFM_FILES}; + std::vector<std::vector<int8_t>> goldenInputFV{NUMBER_OF_IFM_FILES}; + std::vector<std::vector<int8_t>> goldenOutputFV{NUMBER_OF_OFM_FILES}; - std::array<size_t, NUMBER_OF_IFM_FILES> inputSizes = {IFM_0_DATA_SIZE, - IFM_1_DATA_SIZE, - IFM_2_DATA_SIZE, - IFM_3_DATA_SIZE}; + std::array<size_t, NUMBER_OF_IFM_FILES> inputSizes = { + IFM_0_DATA_SIZE, IFM_1_DATA_SIZE, IFM_2_DATA_SIZE, IFM_3_DATA_SIZE}; - std::array<size_t, NUMBER_OF_OFM_FILES> outputSizes = {OFM_0_DATA_SIZE, - OFM_1_DATA_SIZE, - OFM_2_DATA_SIZE, - OFM_3_DATA_SIZE, - OFM_4_DATA_SIZE}; + std::array<size_t, NUMBER_OF_OFM_FILES> outputSizes = { + OFM_0_DATA_SIZE, OFM_1_DATA_SIZE, OFM_2_DATA_SIZE, OFM_3_DATA_SIZE, OFM_4_DATA_SIZE}; - for (uint32_t i = 0 ; i < NUMBER_OF_IFM_FILES; ++i) { + for (uint32_t i = 0; i < NUMBER_OF_IFM_FILES; ++i) { goldenInputFV[i].resize(inputSizes[i]); - std::memcpy(goldenInputFV[i].data(), get_ifm_data_array(i), inputSizes[i]); + std::memcpy(goldenInputFV[i].data(), GetIfmDataArray(i), inputSizes[i]); } - for (uint32_t i = 0 ; i < NUMBER_OF_OFM_FILES; ++i) { + for (uint32_t i = 0; i < NUMBER_OF_OFM_FILES; ++i) { goldenOutputFV[i].resize(outputSizes[i]); - std::memcpy(goldenOutputFV[i].data(), get_ofm_data_array(i), outputSizes[i]); + std::memcpy(goldenOutputFV[i].data(), GetOfmDataArray(i), outputSizes[i]); } DYNAMIC_SECTION("Executing inference with re-init") @@ -146,4 +142,4 @@ namespace noise_reduction { } } /* namespace noise_reduction */ -} /* namespace test */ +} /* namespace test */ diff --git a/tests/use_case/noise_reduction/RNNNoiseUCTests.cc b/tests/use_case/noise_reduction/RNNNoiseUCTests.cc index d835c21..7f9ff19 100644 --- a/tests/use_case/noise_reduction/RNNNoiseUCTests.cc +++ b/tests/use_case/noise_reduction/RNNNoiseUCTests.cc @@ -1,6 +1,6 @@ /* - * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com> - * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates + * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "RNNoiseModel.hpp" -#include "UseCaseHandler.hpp" +#include "BufAttributes.hpp" #include "InputFiles.hpp" +#include "Profiler.hpp" #include "RNNUCTestCaseData.hpp" -#include "BufAttributes.hpp" +#include "RNNoiseModel.hpp" +#include "UseCaseHandler.hpp" #include "hal.h" -#include "Profiler.hpp" #include <catch.hpp> @@ -34,13 +34,13 @@ namespace app { } /* namespace app */ } /* namespace arm */ -#define PLATFORM hal_platform_init(); +#define PLATFORM hal_platform_init(); -#define CONTEXT \ -arm::app::ApplicationContext caseContext; \ -arm::app::Profiler profiler{"noise_reduction"}; \ -caseContext.Set<arm::app::Profiler&>("profiler", profiler); \ -caseContext.Set<arm::app::RNNoiseModel&>("model", model); +#define CONTEXT \ + arm::app::ApplicationContext caseContext; \ + arm::app::Profiler profiler{"noise_reduction"}; \ + caseContext.Set<arm::app::Profiler&>("profiler", profiler); \ + caseContext.Set<arm::app::RNNoiseModel&>("model", model); TEST_CASE("Verify output tensor memory dump") { @@ -56,12 +56,12 @@ TEST_CASE("Verify output tensor memory dump") /* Populate the output tensors */ const size_t numOutputs = model.GetNumOutputs(); - size_t sizeToWrite = 0; - size_t lastTensorSize = model.GetOutputTensor(numOutputs - 1)->bytes; + size_t sizeToWrite = 0; + size_t lastTensorSize = model.GetOutputTensor(numOutputs - 1)->bytes; for (size_t i = 0; i < numOutputs; ++i) { TfLiteTensor* tensor = model.GetOutputTensor(i); - auto* tData = tflite::GetTensorData<uint8_t>(tensor); + auto* tData = tflite::GetTensorData<uint8_t>(tensor); if (tensor->bytes > 0) { memset(tData, static_cast<uint8_t>(i), tensor->bytes); @@ -69,7 +69,6 @@ TEST_CASE("Verify output tensor memory dump") } } - SECTION("Positive use case") { /* Run the memory dump */ @@ -80,7 +79,7 @@ TEST_CASE("Verify output tensor memory dump") size_t k = 0; for (size_t i = 0; i < numOutputs && k < memPool.size(); ++i) { TfLiteTensor* tensor = model.GetOutputTensor(i); - auto* tData = tflite::GetTensorData<uint8_t>(tensor); + auto* tData = tflite::GetTensorData<uint8_t>(tensor); for (size_t j = 0; j < tensor->bytes && k < memPool.size(); ++j) { REQUIRE(tData[j] == memPool[k++]); @@ -126,28 +125,31 @@ TEST_CASE("Inference run all clips", "[RNNoise]") REQUIRE(arm::app::NoiseReductionHandler(caseContext, true)); } -std::function<uint32_t(const uint32_t)> get_golden_input_p232_208_array_size(const uint32_t numberOfFeatures) { +std::function<uint32_t(const uint32_t)> +get_golden_input_p232_208_array_size(const uint32_t numberOfFeatures) +{ - return [numberOfFeatures](const uint32_t) -> uint32_t{ - return numberOfFeatures; - }; + return [numberOfFeatures](const uint32_t) -> uint32_t { return numberOfFeatures; }; } -const char* get_test_filename(const uint32_t idx) { - auto name = get_filename(idx); +const char* get_test_filename(const uint32_t idx) +{ + auto name = GetFilename(idx); REQUIRE(std::string("p232_208.wav") == name); return "p232_208.wav"; } -void testInfByIndex(std::vector<uint32_t>& numberOfInferences) { +void testInfByIndex(std::vector<uint32_t>& numberOfInferences) +{ PLATFORM arm::app::RNNoiseModel model; CONTEXT - caseContext.Set<std::function<const int16_t*(const uint32_t)>>("features", get_audio_array); - caseContext.Set<std::function<const char* (const uint32_t)>>("featureFileNames", get_test_filename); + caseContext.Set<std::function<const int16_t*(const uint32_t)>>("features", GetAudioArray); + caseContext.Set<std::function<const char*(const uint32_t)>>("featureFileNames", + get_test_filename); caseContext.Set<uint32_t>("frameLength", arm::app::rnn::g_FrameLength); caseContext.Set<uint32_t>("frameStride", arm::app::rnn::g_FrameStride); caseContext.Set<uint32_t>("numInputFeatures", arm::app::rnn::g_NumInputFeatures); @@ -160,18 +162,21 @@ void testInfByIndex(std::vector<uint32_t>& numberOfInferences) { size_t oneInferenceOutSizeBytes = arm::app::rnn::g_FrameLength * sizeof(int16_t); auto infIndex = 0; - for (auto numInf: numberOfInferences) { - DYNAMIC_SECTION("Number of features: "<< numInf) { - caseContext.Set<uint32_t>("clipIndex", 1); /* Only getting p232_208.wav for tests. */ + for (auto numInf : numberOfInferences) { + DYNAMIC_SECTION("Number of features: " << numInf) + { + caseContext.Set<uint32_t>("clipIndex", 1); /* Only getting p232_208.wav for tests. */ uint32_t audioSizeInput = numInf * arm::app::rnn::g_FrameLength; - caseContext.Set<std::function<uint32_t(const uint32_t)>>("featureSizes", - get_golden_input_p232_208_array_size(audioSizeInput)); + caseContext.Set<std::function<uint32_t(const uint32_t)>>( + "featureSizes", get_golden_input_p232_208_array_size(audioSizeInput)); - size_t headerNumBytes = 4 + 12 + 4; /* Filename length, filename (12 for p232_208.wav), dump size. */ - size_t footerNumBytes = 4; /* Eof value. */ - size_t memDumpMaxLenBytes = headerNumBytes + footerNumBytes + oneInferenceOutSizeBytes * numInf; + size_t headerNumBytes = + 4 + 12 + 4; /* Filename length, filename (12 for p232_208.wav), dump size. */ + size_t footerNumBytes = 4; /* Eof value. */ + size_t memDumpMaxLenBytes = + headerNumBytes + footerNumBytes + oneInferenceOutSizeBytes * numInf; - std::vector<uint8_t > memDump(memDumpMaxLenBytes); + std::vector<uint8_t> memDump(memDumpMaxLenBytes); size_t undefMemDumpBytesWritten = 0; caseContext.Set<size_t>("MEM_DUMP_LEN", memDumpMaxLenBytes); caseContext.Set<uint8_t*>("MEM_DUMP_BASE_ADDR", memDump.data()); @@ -199,8 +204,9 @@ void testInfByIndex(std::vector<uint32_t>& numberOfInferences) { TEST_CASE("Inference by index - one inference", "[RNNoise]") { - auto totalAudioSize = get_audio_array_size(1); - REQUIRE(64757 == totalAudioSize); /* Checking that the input file is as expected and has not changed. */ + auto totalAudioSize = GetAudioArraySize(1); + REQUIRE(64757 == + totalAudioSize); /* Checking that the input file is as expected and has not changed. */ /* Run 1 inference */ std::vector<uint32_t> numberOfInferences = {1}; @@ -209,8 +215,9 @@ TEST_CASE("Inference by index - one inference", "[RNNoise]") TEST_CASE("Inference by index - several inferences", "[RNNoise]") { - auto totalAudioSize = get_audio_array_size(1); - REQUIRE(64757 == totalAudioSize); /* Checking that the input file is as expected and has not changed. */ + auto totalAudioSize = GetAudioArraySize(1); + REQUIRE(64757 == + totalAudioSize); /* Checking that the input file is as expected and has not changed. */ /* 3 different inference amounts: 1, 2 and all inferences required to cover total feature set */ uint32_t totalInferences = totalAudioSize / arm::app::rnn::g_FrameLength; |