aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-10-31 14:35:58 +0000
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-11-01 09:03:55 +0000
commitfe414cfaecbc83edc29869f32932b9e42d69136f (patch)
tree02806fa5f0969d24be780a27c16cb7c389d17e9d
parentd1f57736b0dd5168e39725f37188239f8ca024d8 (diff)
downloadarmnn-fe414cfaecbc83edc29869f32932b9e42d69136f.tar.gz
IVGCVSW-4050 Add backward compatibility deserialization test for ResizeBilinear
* Added test SerializeResizeBilinear to ensure that ResizeBilinear layers are serialized as Resize layers * Added test EnsureResizeBilinearBackwardCompatibility to ensure the Deserializer is still able to deserialize an old binary that contains a ResizeBilinear layer and that it creates the correct equivalent Resize layer from it Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> Change-Id: If227c5f1f3d027dff7d8f306dee97fd488755a72
-rw-r--r--src/armnnSerializer/test/SerializerTests.cpp122
1 files changed, 120 insertions, 2 deletions
diff --git a/src/armnnSerializer/test/SerializerTests.cpp b/src/armnnSerializer/test/SerializerTests.cpp
index 258d1ee859..4260669124 100644
--- a/src/armnnSerializer/test/SerializerTests.cpp
+++ b/src/armnnSerializer/test/SerializerTests.cpp
@@ -178,7 +178,6 @@ protected:
BOOST_CHECK(descriptor == m_Descriptor);
}
-private:
Descriptor m_Descriptor;
};
@@ -2029,7 +2028,7 @@ BOOST_AUTO_TEST_CASE(SerializeResize)
DECLARE_LAYER_VERIFIER_CLASS_WITH_DESCRIPTOR(Resize)
const std::string layerName("resize");
- const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32);
+ const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32);
const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32);
armnn::ResizeDescriptor desc;
@@ -2055,6 +2054,125 @@ BOOST_AUTO_TEST_CASE(SerializeResize)
deserializedNetwork->Accept(verifier);
}
+class ResizeBilinearLayerVerifier : public LayerVerifierBaseWithDescriptor<armnn::ResizeBilinearDescriptor>
+{
+public:
+ ResizeBilinearLayerVerifier(const std::string& layerName,
+ const std::vector<armnn::TensorInfo>& inputInfos,
+ const std::vector<armnn::TensorInfo>& outputInfos,
+ const armnn::ResizeBilinearDescriptor& descriptor)
+ : LayerVerifierBaseWithDescriptor<armnn::ResizeBilinearDescriptor>(
+ layerName, inputInfos, outputInfos, descriptor) {}
+
+ void VisitResizeLayer(const armnn::IConnectableLayer* layer,
+ const armnn::ResizeDescriptor& descriptor,
+ const char* name) override
+ {
+ VerifyNameAndConnections(layer, name);
+
+ BOOST_CHECK(descriptor.m_Method == armnn::ResizeMethod::Bilinear);
+ BOOST_CHECK(descriptor.m_TargetWidth == m_Descriptor.m_TargetWidth);
+ BOOST_CHECK(descriptor.m_TargetHeight == m_Descriptor.m_TargetHeight);
+ BOOST_CHECK(descriptor.m_DataLayout == m_Descriptor.m_DataLayout);
+ }
+
+ void VisitResizeBilinearLayer(const armnn::IConnectableLayer*,
+ const armnn::ResizeBilinearDescriptor&,
+ const char*) override
+ {
+ throw armnn::Exception("ResizeBilinearLayer should have translated to ResizeLayer");
+ }
+};
+
+// NOTE: Until the deprecated AddResizeBilinearLayer disappears this test checks that
+// calling AddResizeBilinearLayer places a ResizeLayer into the serialized format
+// and that when this deserialises we have a ResizeLayer
+BOOST_AUTO_TEST_CASE(SerializeResizeBilinear)
+{
+ const std::string layerName("resizeBilinear");
+ const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32);
+ const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32);
+
+ armnn::ResizeBilinearDescriptor desc;
+ desc.m_TargetWidth = 4u;
+ desc.m_TargetHeight = 2u;
+
+ armnn::INetworkPtr network = armnn::INetwork::Create();
+ armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0);
+ ARMNN_NO_DEPRECATE_WARN_BEGIN
+ armnn::IConnectableLayer* const resizeLayer = network->AddResizeBilinearLayer(desc, layerName.c_str());
+ ARMNN_NO_DEPRECATE_WARN_END
+ armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0);
+
+ inputLayer->GetOutputSlot(0).Connect(resizeLayer->GetInputSlot(0));
+ resizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
+
+ inputLayer->GetOutputSlot(0).SetTensorInfo(inputInfo);
+ resizeLayer->GetOutputSlot(0).SetTensorInfo(outputInfo);
+
+ armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network));
+ BOOST_CHECK(deserializedNetwork);
+
+ ResizeBilinearLayerVerifier verifier(layerName, {inputInfo}, {outputInfo}, desc);
+ deserializedNetwork->Accept(verifier);
+}
+
+BOOST_AUTO_TEST_CASE(EnsureResizeBilinearBackwardCompatibility)
+{
+ // The hex data below is a flat buffer containing a simple network with an input,
+ // a ResizeBilinearLayer (now deprecated) and an output
+ //
+ // This test verifies that we can still deserialize this old-style model by replacing
+ // the ResizeBilinearLayer with an equivalent ResizeLayer
+ const std::vector<uint8_t> resizeBilinearModel =
+ {
+ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x0A, 0x00,
+ 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
+ 0x50, 0x01, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xD4, 0xFE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0B,
+ 0x04, 0x00, 0x00, 0x00, 0xC2, 0xFE, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00,
+ 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8A, 0xFF, 0xFF, 0xFF, 0x02, 0x00, 0x00, 0x00,
+ 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x38, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
+ 0x00, 0x1A, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0E, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00,
+ 0x34, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x12, 0x00, 0x08, 0x00, 0x0C, 0x00,
+ 0x07, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x0E, 0x00, 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0E, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x72, 0x65, 0x73, 0x69, 0x7A, 0x65, 0x42, 0x69, 0x6C, 0x69,
+ 0x6E, 0x65, 0x61, 0x72, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x52, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0xF6, 0xFF, 0xFF, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
+ 0x0A, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x14, 0x00,
+ 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0A, 0x00,
+ 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x10, 0x00,
+ 0x08, 0x00, 0x07, 0x00, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00,
+ 0x00, 0x00, 0x05, 0x00, 0x00, 0x00
+ };
+
+ armnn::INetworkPtr deserializedNetwork =
+ DeserializeNetwork(std::string(resizeBilinearModel.begin(), resizeBilinearModel.end()));
+ BOOST_CHECK(deserializedNetwork);
+
+ const armnn::TensorInfo inputInfo = armnn::TensorInfo({1, 3, 5, 5}, armnn::DataType::Float32);
+ const armnn::TensorInfo outputInfo = armnn::TensorInfo({1, 3, 2, 4}, armnn::DataType::Float32);
+
+ armnn::ResizeBilinearDescriptor descriptor;
+ descriptor.m_TargetWidth = 4u;
+ descriptor.m_TargetHeight = 2u;
+
+ ResizeBilinearLayerVerifier verifier("resizeBilinear", { inputInfo }, { outputInfo }, descriptor);
+ deserializedNetwork->Accept(verifier);
+}
+
BOOST_AUTO_TEST_CASE(SerializeRsqrt)
{
DECLARE_LAYER_VERIFIER_CLASS(Rsqrt)