diff options
author | Sadik Armagan <sadik.armagan@arm.com> | 2020-11-10 21:18:41 +0000 |
---|---|---|
committer | Sadik Armagan <sadik.armagan@arm.com> | 2020-11-10 21:18:41 +0000 |
commit | 6e36a64e26520e3f169bb2a92972a24e1be915a7 (patch) | |
tree | 5b1f9187fc297d34cb34328ac6aa447b9026e657 /delegate/src/test/FullyConnectedTest.cpp | |
parent | 50c87d39173cb48fc216ccb585714b669b095611 (diff) | |
download | armnn-6e36a64e26520e3f169bb2a92972a24e1be915a7.tar.gz |
IVGCVSW-5389 'TfLiteDelegate: Implement the FullyConnected operator'
* Added FullyConnected operator support to delegate
Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Change-Id: Iae9c0980a4bfd6aa4d90f107f329dfa782baeefe
Diffstat (limited to 'delegate/src/test/FullyConnectedTest.cpp')
-rw-r--r-- | delegate/src/test/FullyConnectedTest.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/delegate/src/test/FullyConnectedTest.cpp b/delegate/src/test/FullyConnectedTest.cpp new file mode 100644 index 0000000000..1d33381d6e --- /dev/null +++ b/delegate/src/test/FullyConnectedTest.cpp @@ -0,0 +1,128 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "FullyConnectedTestHelper.hpp" + +namespace +{ + +TEST_SUITE("FullyConnectedTest") +{ + +void FullyConnectedFp32Test(std::vector<armnn::BackendId>& backends) +{ + std::vector<int32_t> inputTensorShape { 1, 4, 1, 1 }; + std::vector<int32_t> weightsTensorShape { 1, 4 }; + std::vector<int32_t> biasTensorShape { 1 }; + std::vector<int32_t> outputTensorShape { 1, 1 }; + + std::vector<float> inputValues = { 10, 20, 30, 40 }; + std::vector<float> weightsData = { 2, 3, 4, 5 }; + + std::vector<float> expectedOutputValues = { (400 + 10) }; + + // bias is set std::vector<float> biasData = { 10 } in the model + FullyConnectedTest<float>(backends, + ::tflite::TensorType_FLOAT32, + tflite::ActivationFunctionType_NONE, + inputTensorShape, + weightsTensorShape, + biasTensorShape, + outputTensorShape, + inputValues, + expectedOutputValues, + weightsData); +} + +void FullyConnectedActicationTest(std::vector<armnn::BackendId>& backends) +{ + std::vector<int32_t> inputTensorShape { 1, 4, 1, 1 }; + std::vector<int32_t> weightsTensorShape { 1, 4 }; + std::vector<int32_t> biasTensorShape { 1 }; + std::vector<int32_t> outputTensorShape { 1, 1 }; + + std::vector<float> inputValues = { -10, 20, 30, 40 }; + std::vector<float> weightsData = { 2, 3, 4, -5 }; + + std::vector<float> expectedOutputValues = { 0 }; + + // bias is set std::vector<float> biasData = { 10 } in the model + FullyConnectedTest<float>(backends, + ::tflite::TensorType_FLOAT32, + tflite::ActivationFunctionType_RELU, + inputTensorShape, + weightsTensorShape, + biasTensorShape, + outputTensorShape, + inputValues, + expectedOutputValues, + weightsData); +} + +void FullyConnectedUint8Test(std::vector<armnn::BackendId>& backends) +{ + std::vector<int32_t> inputTensorShape { 1, 4, 2, 1 }; + std::vector<int32_t> weightsTensorShape { 1, 4 }; + std::vector<int32_t> biasTensorShape { 1 }; + std::vector<int32_t> outputTensorShape { 2, 1 }; + + std::vector<uint8_t> inputValues = { 1, 2, 3, 4, 10, 20, 30, 40 }; + std::vector<uint8_t> weightsData = { 2, 3, 4, 5 }; + + std::vector<uint8_t> expectedOutputValues = { (40 + 10) / 2, (400 + 10) / 2 }; + + // bias is set std::vector<int32_t> biasData = { 10 } in the model + // input and weights quantization scale 1.0f and offset 0 in the model + // output quantization scale 2.0f and offset 0 in the model + FullyConnectedTest<uint8_t>(backends, + ::tflite::TensorType_UINT8, + tflite::ActivationFunctionType_NONE, + inputTensorShape, + weightsTensorShape, + biasTensorShape, + outputTensorShape, + inputValues, + expectedOutputValues, + weightsData); +} + +TEST_CASE ("FULLY_CONNECTED_FP32_GpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc, + armnn::Compute::CpuRef }; + FullyConnectedFp32Test(backends); +} + +TEST_CASE ("FULLY_CONNECTED_FP32_CpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, + armnn::Compute::CpuRef }; + FullyConnectedFp32Test(backends); +} + +TEST_CASE ("FULLY_CONNECTED_UINT8_GpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc, + armnn::Compute::CpuRef }; + FullyConnectedUint8Test(backends); +} + +TEST_CASE ("FULLY_CONNECTED_UINT8_CpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc, + armnn::Compute::CpuRef }; + FullyConnectedUint8Test(backends); +} + +TEST_CASE ("FULLY_CONNECTED_Activation_GpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc, + armnn::Compute::CpuRef }; + FullyConnectedActicationTest(backends); +} + +} // End of TEST_SUITE("FullyConnectedTest") + +} // anonymous namespace
\ No newline at end of file |