IVGCVSW-3650 Fix Transpose Convolution inputs in TfLite parser
authorMatthew Jackson <matthew.jackson@arm.com>
Tue, 20 Aug 2019 16:18:33 +0000 (17:18 +0100)
committerÁron Virginás-Tar <aron.virginas-tar@arm.com>
Wed, 21 Aug 2019 12:09:47 +0000 (12:09 +0000)
* Reordered and edited inputs in ParseTransposeConv method
* Updated test cases to reflect changes

Signed-off-by: Matthew Jackson <matthew.jackson@arm.com>
Change-Id: Icd090cf6ab340eed4f098ef8641daf7c6e0d0949

src/armnnTfLiteParser/TfLiteParser.cpp
src/armnnTfLiteParser/test/TransposeConv.cpp

index 0e11a5c..d1cef31 100644 (file)
@@ -879,12 +879,12 @@ void TfLiteParser::ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex
     desc.m_DataLayout = armnn::DataLayout::NHWC;
 
     auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex);
-    CHECK_VALID_SIZE(inputs.size(), 2, 3);
+    CHECK_VALID_SIZE(inputs.size(), 3);
 
     auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex);
     CHECK_VALID_SIZE(outputs.size(), 1);
 
-    armnn::TensorInfo inputTensorInfo  = ToTensorInfo(inputs[0]);
+    armnn::TensorInfo inputTensorInfo  = ToTensorInfo(inputs[2]);
     armnn::TensorInfo filterTensorInfo = ToTensorInfo(inputs[1]);
 
     // TfLite uses NHWC tensors
@@ -917,25 +917,10 @@ void TfLiteParser::ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex
     armnn::IConnectableLayer* layer = nullptr;
     auto layerName = boost::str(boost::format("TransposeConv:%1%:%2%") % subgraphIndex % operatorIndex);
 
-    if (inputs.size() == 3)
-    {
-        desc.m_BiasEnabled = true;
-        armnn::TensorInfo biasTensorInfo = ToTensorInfo(inputs[2]);
-        auto biasTensorAndData = CreateConstTensor(inputs[2],
-                                                   biasTensorInfo,
-                                                   armnn::Optional<armnn::PermutationVector&>());
-        layer = m_Network->AddTransposeConvolution2dLayer(desc,
-                                                          filterTensorAndData.first,
-                                                          Optional<ConstTensor>(biasTensorAndData.first),
-                                                          layerName.c_str());
-    }
-    else
-    {
-        layer = m_Network->AddTransposeConvolution2dLayer(desc,
-                                                          filterTensorAndData.first,
-                                                          EmptyOptional(),
-                                                          layerName.c_str());
-    }
+    layer = m_Network->AddTransposeConvolution2dLayer(desc,
+                                                      filterTensorAndData.first,
+                                                      EmptyOptional(),
+                                                      layerName.c_str());
 
     BOOST_ASSERT(layer != nullptr);
 
@@ -944,7 +929,7 @@ void TfLiteParser::ParseTransposeConv(size_t subgraphIndex, size_t operatorIndex
 
     // only the tensors for the inputs are relevant, exclude the const (filter) tensor
     auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex));
-    RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]});
+    RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[2]});
 
     auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
     RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
index 05b48ec..53212b5 100644 (file)
@@ -15,31 +15,10 @@ struct TransposeConvFixture : public ParserFlatbuffersFixture
                                   const std::string& outputShape,
                                   const std::string& filterShape,
                                   const std::string& filterData,
-                                  const bool biasEnabled,
-                                  const std::string& biasShape,
-                                  const std::string& biasData,
                                   const std::string& strideX,
                                   const std::string& strideY,
                                   const std::string& dataType)
     {
-        std::string biasString;
-        if (biasEnabled)
-        {
-            biasString = R"(
-                        {
-                            "shape": )" + biasShape + R"(,
-                            "type": "INT32",
-                            "buffer": 2,
-                            "name": "biasTensor",
-                            "quantization": {
-                                "min": [ 0.0 ],
-                                "max": [ 255.0 ],
-                                "scale": [ 1.0 ],
-                                "zero_point": [ 0 ],
-                            }
-                        },)";
-
-        }
         m_JsonString = R"(
             {
                 "version": 3,
@@ -47,10 +26,10 @@ struct TransposeConvFixture : public ParserFlatbuffersFixture
                 "subgraphs": [ {
                     "tensors": [
                         {
-                            "shape": )" + inputShape + R"(,
-                            "type": ")" + dataType + R"(",
+                            "shape": [ 4 ],
+                            "type": "UINT8",
                             "buffer": 0,
-                            "name": "inputTensor",
+                            "name": "outputShapeTensor",
                             "quantization": {
                                 "min": [ 0.0 ],
                                 "max": [ 255.0 ],
@@ -69,11 +48,23 @@ struct TransposeConvFixture : public ParserFlatbuffersFixture
                                 "scale": [ 1.0 ],
                                 "zero_point": [ 0 ],
                             }
-                        },)" + biasString + R"(
+                        },
+                        {
+                            "shape": )" + inputShape + R"(,
+                            "type": ")" + dataType + R"(",
+                            "buffer": 2,
+                            "name": "inputTensor",
+                            "quantization": {
+                                "min": [ 0.0 ],
+                                "max": [ 255.0 ],
+                                "scale": [ 1.0 ],
+                                "zero_point": [ 0 ],
+                            }
+                        },
                         {
                             "shape": )" + outputShape + R"(,
                             "type": ")" + dataType + R"(",
-                            "buffer": )" + (biasEnabled ? "3" : "2") + R"(,
+                            "buffer": 3,
                             "name": "outputTensor",
                             "quantization": {
                                 "min": [ 0.0 ],
@@ -83,13 +74,13 @@ struct TransposeConvFixture : public ParserFlatbuffersFixture
                             }
                         }
                     ],
-                    "inputs": [ 0 ],
-                    "outputs": [ )" + (biasEnabled ? "3" : "2") + R"( ],
+                    "inputs": [ 2 ],
+                    "outputs": [ 3 ],
                     "operators": [
                         {
                             "opcode_index": 0,
-                            "inputs": [ 0, 1)" + (biasEnabled ? ", 2" : "") + R"( ],
-                            "outputs": [ )" + (biasEnabled ? "3" : "2") + R"( ],
+                            "inputs": [ 0, 1, 2 ],
+                            "outputs": [ 3 ],
                             "builtin_options_type": "TransposeConvOptions",
                             "builtin_options": {
                                 "padding": "SAME",
@@ -101,9 +92,9 @@ struct TransposeConvFixture : public ParserFlatbuffersFixture
                     ],
                 } ],
                 "buffers" : [
-                    { },
+                    { "data": )" + outputShape + R"( },
                     { "data": )" + filterData + R"( },
-                    { )" + (biasEnabled ? (R"("data": )" + biasData) : "") + R"( },
+                    { },
                     { }
                 ]
             }
@@ -119,9 +110,6 @@ struct SimpleTransposeConvFixture : TransposeConvFixture
                            "[ 1, 3, 3, 1 ]",  // outputShape
                            "[ 1, 2, 2, 1 ]",  // filterShape
                            "[ 0, 1, 2, 4 ]",  // filterData
-                           false,             // biasEnabled
-                           "",                // biasShape
-                           "",                // biasData
                            "1",               // strideX
                            "1",               // strideY
                            "UINT8")           // dataType
@@ -143,35 +131,4 @@ BOOST_FIXTURE_TEST_CASE( ParseSimpleTransposeConv, SimpleTransposeConvFixture )
         });
 }
 
-struct TransposeConvWithBiasFixture : TransposeConvFixture
-{
-    TransposeConvWithBiasFixture()
-    : TransposeConvFixture("[ 1, 2, 2, 1 ]",  // inputShape
-                           "[ 1, 3, 3, 1 ]",  // outputShape
-                           "[ 1, 2, 2, 1 ]",  // filterShape
-                           "[ 0, 1, 2, 4 ]",  // filterData
-                           true,              // biasEnabled
-                           "[ 1 ]",           // biasShape
-                           "[ 2, 0, 0, 0 ]",  // biasData
-                           "1",               // strideX
-                           "1",               // strideY
-                           "UINT8")           // dataType
-    {}
-};
-
-BOOST_FIXTURE_TEST_CASE( ParseTransposeConvWithBias, TransposeConvWithBiasFixture )
-{
-    RunTest<4, armnn::DataType::QuantisedAsymm8>(
-        0,
-        {
-            1, 2,
-            3, 4
-        },
-        {
-            2, 3,  5,
-            4, 13, 14,
-            8, 22, 18
-        });
-}
-
 BOOST_AUTO_TEST_SUITE_END()