summaryrefslogtreecommitdiff
path: root/tests/use_case
diff options
context:
space:
mode:
authorRichard Burton <richard.burton@arm.com>2022-10-05 11:00:37 +0100
committerRichard Burton <richard.burton@arm.com>2022-10-06 14:08:13 +0100
commitec5e99be3ae6dd0d3811950f155b01e144431452 (patch)
treea5d6c4dd9267db2465063b8d0e1a5cb6d19dac8d /tests/use_case
parent890b2b89cacc6f2291596a001d555d374c8c9edd (diff)
downloadml-embedded-evaluation-kit-ec5e99be3ae6dd0d3811950f155b01e144431452.tar.gz
MLECO-3164: Additional refactoring of KWS API
Part 1 * Add KwsClassifier * KwsPostProcess can now be told to average results * Averaging is handlded by KwsClassifier * Current sliding window index is now an argument of DoPreProcess Change-Id: I07626da595ad1cbd982e8366f0d1bb56d1040459
Diffstat (limited to 'tests/use_case')
-rw-r--r--tests/use_case/img_class/ImgClassificationUCTest.cc3
-rw-r--r--tests/use_case/kws/KWSHandlerTest.cc3
-rw-r--r--tests/use_case/kws/KwsClassifierTests.cc125
-rw-r--r--tests/use_case/noise_reduction/RNNNoiseUCTests.cc8
-rw-r--r--tests/use_case/object_detection/InferenceTestYoloFastest.cc2
-rw-r--r--tests/use_case/vww/VisualWakeWordUCTests.cc3
6 files changed, 136 insertions, 8 deletions
diff --git a/tests/use_case/img_class/ImgClassificationUCTest.cc b/tests/use_case/img_class/ImgClassificationUCTest.cc
index 1685e5f..78700dc 100644
--- a/tests/use_case/img_class/ImgClassificationUCTest.cc
+++ b/tests/use_case/img_class/ImgClassificationUCTest.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +21,7 @@
#include "MobileNetModel.hpp"
#include "UseCaseHandler.hpp"
#include "UseCaseCommonUtils.hpp"
+#include "BufAttributes.hpp"
#include <catch.hpp>
diff --git a/tests/use_case/kws/KWSHandlerTest.cc b/tests/use_case/kws/KWSHandlerTest.cc
index db67e54..413e089 100644
--- a/tests/use_case/kws/KWSHandlerTest.cc
+++ b/tests/use_case/kws/KWSHandlerTest.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@
#include "UseCaseHandler.hpp"
#include "Classifier.hpp"
#include "UseCaseCommonUtils.hpp"
+#include "BufAttributes.hpp"
namespace arm {
namespace app {
diff --git a/tests/use_case/kws/KwsClassifierTests.cc b/tests/use_case/kws/KwsClassifierTests.cc
new file mode 100644
index 0000000..92fb15e
--- /dev/null
+++ b/tests/use_case/kws/KwsClassifierTests.cc
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2022 Arm Limited. All rights reserved.
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "KwsClassifier.hpp"
+
+#include <catch.hpp>
+
+TEST_CASE("Test invalid classifier")
+{
+ TfLiteTensor* outputTens = nullptr;
+ std::vector<arm::app::ClassificationResult> resultVec;
+ arm::app::KwsClassifier classifier;
+ std::vector<std::vector<float>> resultHistory;
+ REQUIRE(!classifier.GetClassificationResults(outputTens, resultVec, {}, 5, true, resultHistory));
+}
+
+TEST_CASE("Test valid classifier, average=0 should be same as 1)")
+{
+ int dimArray[] = {1, 5};
+ std::vector<std::string> labels(5);
+ std::vector<uint8_t> outputVec = {0, 1, 2, 3, 4};
+ std::vector<std::vector<float>> resultHistory = {};
+ TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
+ TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
+ outputVec.data(), dims, 1, 0);
+ TfLiteTensor* outputTensor = &tfTensor;
+ std::vector<arm::app::ClassificationResult> resultVec;
+ arm::app::KwsClassifier classifier;
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 4);
+ REQUIRE(resultVec[0].m_normalisedVal == 4);
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 4);
+ REQUIRE(resultVec[0].m_normalisedVal == 4);
+
+ std::vector<std::vector<float>> expectedHistory = {};
+ REQUIRE(resultHistory == expectedHistory);
+}
+
+TEST_CASE("Test valid classifier UINT8, average=1, softmax=false")
+{
+ int dimArray[] = {1, 5};
+ std::vector<std::string> labels(5);
+ std::vector<uint8_t> outputVec = {0, 1, 2, 3, 4};
+ std::vector<std::vector<float>> resultHistory = {{0, 0, 0, 0, 0}};
+ TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
+ TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
+ outputVec.data(), dims, 1, 0);
+ TfLiteTensor* outputTensor = &tfTensor;
+ std::vector<arm::app::ClassificationResult> resultVec;
+ arm::app::KwsClassifier classifier;
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 4);
+ REQUIRE(resultVec[0].m_normalisedVal == 4);
+
+ /* We do not update history if not >1 in size. */
+ std::vector<std::vector<float>> expectedHistory = {{0, 0, 0, 0, 0}};
+ REQUIRE(resultHistory == expectedHistory);
+}
+
+TEST_CASE("Test valid classifier UINT8, average=2")
+{
+ int dimArray[] = {1, 5};
+ std::vector<std::string> labels(5);
+ std::vector<uint8_t> outputVec = {0, 1, 2, 3, 4};
+ std::vector<std::vector<float>> resultHistory = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}};
+ TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
+ TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
+ outputVec.data(), dims, 1, 0);
+ TfLiteTensor* outputTensor = &tfTensor;
+ std::vector<arm::app::ClassificationResult> resultVec;
+ arm::app::KwsClassifier classifier;
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 4);
+ REQUIRE(resultVec[0].m_normalisedVal == 2);
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 4);
+ REQUIRE(resultVec[0].m_normalisedVal == 4);
+
+ std::vector<std::vector<float>> expectedHistory = {{0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}};
+ REQUIRE(resultHistory == expectedHistory);
+}
+
+TEST_CASE("Test valid classifier int8, average=0")
+{
+ int dimArray[] = {1, 5};
+ std::vector<std::string> labels(5);
+ std::vector<int8_t> outputVec = {-2, -1, 0, 2, 1};
+ std::vector<std::vector<float>> resultHistory = {};
+ TfLiteIntArray* dims= tflite::testing::IntArrayFromInts(dimArray);
+ TfLiteTensor tfTensor = tflite::testing::CreateQuantizedTensor(
+ outputVec.data(), dims, 1, 0);
+ TfLiteTensor* outputTensor = &tfTensor;
+ std::vector<arm::app::ClassificationResult> resultVec;
+ arm::app::KwsClassifier classifier;
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 3);
+ REQUIRE(resultVec[0].m_normalisedVal == 2);
+
+ REQUIRE(classifier.GetClassificationResults(outputTensor, resultVec, labels, 1, false, resultHistory));
+ REQUIRE(resultVec[0].m_labelIdx == 3);
+ REQUIRE(resultVec[0].m_normalisedVal == 2);
+
+ std::vector<std::vector<float>> expectedHistory = {};
+ REQUIRE(resultHistory == expectedHistory);
+} \ No newline at end of file
diff --git a/tests/use_case/noise_reduction/RNNNoiseUCTests.cc b/tests/use_case/noise_reduction/RNNNoiseUCTests.cc
index 310814f..144fc9f 100644
--- a/tests/use_case/noise_reduction/RNNNoiseUCTests.cc
+++ b/tests/use_case/noise_reduction/RNNNoiseUCTests.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,11 +18,11 @@
#include "UseCaseHandler.hpp"
#include "InputFiles.hpp"
#include "RNNUCTestCaseData.hpp"
-#include "UseCaseCommonUtils.hpp"
+#include "BufAttributes.hpp"
+#include "hal.h"
+#include "Profiler.hpp"
#include <catch.hpp>
-#include <hal.h>
-#include <Profiler.hpp>
namespace arm {
namespace app {
diff --git a/tests/use_case/object_detection/InferenceTestYoloFastest.cc b/tests/use_case/object_detection/InferenceTestYoloFastest.cc
index d328684..ff70bf9 100644
--- a/tests/use_case/object_detection/InferenceTestYoloFastest.cc
+++ b/tests/use_case/object_detection/InferenceTestYoloFastest.cc
@@ -20,7 +20,7 @@
#include "TensorFlowLiteMicro.hpp"
#include "DetectorPostProcessing.hpp"
#include "InputFiles.hpp"
-#include "UseCaseCommonUtils.hpp"
+#include "BufAttributes.hpp"
namespace arm {
namespace app {
diff --git a/tests/use_case/vww/VisualWakeWordUCTests.cc b/tests/use_case/vww/VisualWakeWordUCTests.cc
index fe3782b..96c1346 100644
--- a/tests/use_case/vww/VisualWakeWordUCTests.cc
+++ b/tests/use_case/vww/VisualWakeWordUCTests.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@
#include "UseCaseHandler.hpp"
#include "Classifier.hpp"
#include "UseCaseCommonUtils.hpp"
+#include "BufAttributes.hpp"
namespace arm {
namespace app {