diff options
Diffstat (limited to 'delegate/test/NormalizationTestHelper.hpp')
-rw-r--r-- | delegate/test/NormalizationTestHelper.hpp | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/delegate/test/NormalizationTestHelper.hpp b/delegate/test/NormalizationTestHelper.hpp index eafdf84835..a9db6b8fbf 100644 --- a/delegate/test/NormalizationTestHelper.hpp +++ b/delegate/test/NormalizationTestHelper.hpp @@ -8,14 +8,14 @@ #include "TestUtils.hpp" #include <armnn_delegate.hpp> +#include <DelegateTestInterpreter.hpp> #include <flatbuffers/flatbuffers.h> -#include <tensorflow/lite/interpreter.h> #include <tensorflow/lite/kernels/register.h> -#include <tensorflow/lite/model.h> -#include <schema_generated.h> #include <tensorflow/lite/version.h> +#include <schema_generated.h> + #include <doctest/doctest.h> namespace @@ -110,7 +110,7 @@ std::vector<char> CreateNormalizationTfLiteModel(tflite::BuiltinOperator normali modelDescription, flatBufferBuilder.CreateVector(buffers.data(), buffers.size())); - flatBufferBuilder.Finish(flatbufferModel); + flatBufferBuilder.Finish(flatbufferModel, armnnDelegate::FILE_IDENTIFIER); return std::vector<char>(flatBufferBuilder.GetBufferPointer(), flatBufferBuilder.GetBufferPointer() + flatBufferBuilder.GetSize()); @@ -131,7 +131,7 @@ void NormalizationTest(tflite::BuiltinOperator normalizationOperatorCode, float quantScale = 1.0f, int quantOffset = 0) { - using namespace tflite; + using namespace delegateTestInterpreter; std::vector<char> modelBuffer = CreateNormalizationTfLiteModel(normalizationOperatorCode, tensorType, inputShape, @@ -143,40 +143,27 @@ void NormalizationTest(tflite::BuiltinOperator normalizationOperatorCode, quantScale, quantOffset); - const Model* tfLiteModel = GetModel(modelBuffer.data()); - CHECK(tfLiteModel != nullptr); - - std::unique_ptr<Interpreter> armnnDelegateInterpreter; - CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) - (&armnnDelegateInterpreter) == kTfLiteOk); - CHECK(armnnDelegateInterpreter != nullptr); - CHECK(armnnDelegateInterpreter->AllocateTensors() == kTfLiteOk); - - std::unique_ptr<Interpreter> tfLiteInterpreter; - CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) - (&tfLiteInterpreter) == kTfLiteOk); - CHECK(tfLiteInterpreter != nullptr); - CHECK(tfLiteInterpreter->AllocateTensors() == kTfLiteOk); - - // Create the ArmNN Delegate - armnnDelegate::DelegateOptions delegateOptions(backends); - std::unique_ptr<TfLiteDelegate, decltype(&armnnDelegate::TfLiteArmnnDelegateDelete)> - theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions), - armnnDelegate::TfLiteArmnnDelegateDelete); - CHECK(theArmnnDelegate != nullptr); - // Modify armnnDelegateInterpreter to use armnnDelegate - CHECK(armnnDelegateInterpreter->ModifyGraphWithDelegate(theArmnnDelegate.get()) == kTfLiteOk); - - // Set input data - armnnDelegate::FillInput<T>(tfLiteInterpreter, 0, inputValues); - armnnDelegate::FillInput<T>(armnnDelegateInterpreter, 0, inputValues); - - // Run EnqueueWorkload - CHECK(tfLiteInterpreter->Invoke() == kTfLiteOk); - CHECK(armnnDelegateInterpreter->Invoke() == kTfLiteOk); - - // Compare output data - armnnDelegate::CompareOutputData(tfLiteInterpreter, armnnDelegateInterpreter, outputShape, expectedOutputValues); + // Setup interpreter with just TFLite Runtime. + auto tfLiteInterpreter = DelegateTestInterpreter(modelBuffer); + CHECK(tfLiteInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(tfLiteInterpreter.FillInputTensor<T>(inputValues, 0) == kTfLiteOk); + CHECK(tfLiteInterpreter.Invoke() == kTfLiteOk); + std::vector<T> tfLiteOutputValues = tfLiteInterpreter.GetOutputResult<T>(0); + std::vector<int32_t> tfLiteOutputShape = tfLiteInterpreter.GetOutputShape(0); + + // Setup interpreter with Arm NN Delegate applied. + auto armnnInterpreter = DelegateTestInterpreter(modelBuffer, backends); + CHECK(armnnInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(armnnInterpreter.FillInputTensor<T>(inputValues, 0) == kTfLiteOk); + CHECK(armnnInterpreter.Invoke() == kTfLiteOk); + std::vector<T> armnnOutputValues = armnnInterpreter.GetOutputResult<T>(0); + std::vector<int32_t> armnnOutputShape = armnnInterpreter.GetOutputShape(0); + + armnnDelegate::CompareOutputData<T>(tfLiteOutputValues, armnnOutputValues, expectedOutputValues); + armnnDelegate::CompareOutputShape(tfLiteOutputShape, armnnOutputShape, outputShape); + + tfLiteInterpreter.Cleanup(); + armnnInterpreter.Cleanup(); } void L2NormalizationTest(std::vector<armnn::BackendId>& backends) |