biasTensorInfo = armnn::TensorInfo(armnn::TensorShape({1}), GetDataType(tfLiteInputTensor));
}
+ armnn::TensorInfo reshapedTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
+
+ if (inputTensorInfo.GetNumDimensions() > 2)
+ {
+ // Calculate reshape to flatten to 2D [batch_size, input_size]
+ std::vector<unsigned int> reshapedDimensions(2);
+ reshapedDimensions[1] = weightsTensorInfo.GetShape()[1];
+ reshapedDimensions[0] = inputTensorInfo.GetNumElements() / reshapedDimensions[1];
+
+ if (inputTensorInfo.GetNumElements() % reshapedDimensions[1] != 0)
+ {
+ TF_LITE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnDelegate: Failed to deduce input tensor shape from filter size #%d #%d node #%d: ",
+ reshapedDimensions[1], operatorCode, nodeIndex);
+ return kTfLiteError;
+ }
+
+ reshapedTensorInfo.SetShape(armnn::TensorShape{ 2, reshapedDimensions.data() });
+ }
+
armnn::FullyConnectedDescriptor descriptor;
descriptor.m_TransposeWeightMatrix = true;
descriptor.m_BiasEnabled = biasEnabled;
IsFullyConnectedSupported,
delegateData.m_Backends,
isSupported,
- inputTensorInfo,
+ reshapedTensorInfo,
outputTensorInfo,
weightsTensorInfo,
biasTensorInfo,
if (inputTensorInfo.GetNumDimensions() > 2)
{
// Add reshape to flatten to 2D [batch_size, input_size]
- std::vector<unsigned int> reshapedDimensions(2);
- reshapedDimensions[1] = weightsTensorInfo.GetShape()[1];
- reshapedDimensions[0] = inputTensorInfo.GetNumElements() / reshapedDimensions[1];
-
- if (inputTensorInfo.GetNumElements() % reshapedDimensions[1] != 0)
- {
- TF_LITE_MAYBE_KERNEL_LOG(
- tfLiteContext,
- "TfLiteArmnnDelegate: Failed to deduce input tensor shape from filter size #%d #%d node #%d: ",
- reshapedDimensions[1], operatorCode, nodeIndex);
- return kTfLiteError;
- }
-
- armnn::TensorInfo reshapedTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- reshapedTensorInfo.SetShape(armnn::TensorShape{ 2, reshapedDimensions.data() });
-
armnn::ReshapeDescriptor reshapeDescriptor;
reshapeDescriptor.m_TargetShape = reshapedTensorInfo.GetShape();
reshapeLayer = delegateData.m_Network->AddReshapeLayer(reshapeDescriptor);
// Connect
delegateData.m_OutputSlotForNode[tfLiteNode->inputs->data[0]]->Connect(reshapeLayer->GetInputSlot(0));
reshapeLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
- armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
delegateData.m_OutputSlotForNode[tfLiteNode->outputs->data[0]] = &outputSlot;
}
namespace
{
-TEST_SUITE("FullyConnectedTest")
-{
-
void FullyConnectedFp32Test(std::vector<armnn::BackendId>& backends)
{
std::vector<int32_t> inputTensorShape { 1, 4, 1, 1 };
weightsData);
}
-void FullyConnectedUint8Test(std::vector<armnn::BackendId>& backends)
+void FullyConnectedInt8Test(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<int8_t> inputValues = { 1, 2, 3, 4, 5, 10, 15, 20 };
+ std::vector<int8_t> weightsData = { 2, 3, 4, 5 };
- std::vector<uint8_t> expectedOutputValues = { (40 + 10) / 2, (400 + 10) / 2 };
+ std::vector<int8_t> expectedOutputValues = { 25, 105 }; // (40 + 10) / 2, (200 + 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);
+ FullyConnectedTest<int8_t>(backends,
+ ::tflite::TensorType_INT8,
+ tflite::ActivationFunctionType_NONE,
+ inputTensorShape,
+ weightsTensorShape,
+ biasTensorShape,
+ outputTensorShape,
+ inputValues,
+ expectedOutputValues,
+ weightsData);
}
-TEST_CASE ("FULLY_CONNECTED_FP32_GpuAcc_Test")
+TEST_SUITE("FullyConnected_GpuAccTests")
+{
+
+TEST_CASE ("FullyConnected_FP32_GpuAcc_Test")
{
- std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
- armnn::Compute::CpuRef };
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
FullyConnectedFp32Test(backends);
}
-TEST_CASE ("FULLY_CONNECTED_FP32_CpuAcc_Test")
+TEST_CASE ("FullyConnected_Int8_GpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ FullyConnectedInt8Test(backends);
+}
+
+TEST_CASE ("FullyConnected_Activation_GpuAcc_Test")
{
- std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc,
- armnn::Compute::CpuRef };
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ FullyConnectedActicationTest(backends);
+}
+
+} // End of TEST_SUITE("FullyConnected_GpuAccTests")
+
+TEST_SUITE("FullyConnected_CpuAccTests")
+{
+
+TEST_CASE ("FullyConnected_FP32_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
FullyConnectedFp32Test(backends);
}
-TEST_CASE ("FULLY_CONNECTED_UINT8_GpuAcc_Test")
+TEST_CASE ("FullyConnected_Int8_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ FullyConnectedInt8Test(backends);
+}
+
+TEST_CASE ("FullyConnected_Activation_CpuAcc_Test")
{
- std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
- armnn::Compute::CpuRef };
- FullyConnectedUint8Test(backends);
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ FullyConnectedActicationTest(backends);
+}
+
+} // End of TEST_SUITE("FullyConnected_CpuAccTests")
+
+TEST_SUITE("FullyConnected_CpuRefTests")
+{
+
+TEST_CASE ("FullyConnected_FP32_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ FullyConnectedFp32Test(backends);
}
-TEST_CASE ("FULLY_CONNECTED_UINT8_CpuAcc_Test")
+TEST_CASE ("FullyConnected_Int8_CpuRef_Test")
{
- std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
- armnn::Compute::CpuRef };
- FullyConnectedUint8Test(backends);
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ FullyConnectedInt8Test(backends);
}
-TEST_CASE ("FULLY_CONNECTED_Activation_GpuAcc_Test")
+TEST_CASE ("FullyConnected_Activation_CpuRef_Test")
{
- std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
- armnn::Compute::CpuRef };
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
FullyConnectedActicationTest(backends);
}
-} // End of TEST_SUITE("FullyConnectedTest")
+} // End of TEST_SUITE("FullyConnected_CpuRefTests")
} // anonymous namespace
\ No newline at end of file