IVGCVSW-3366 Add Quantizer support for ResizeLayer
authorTeresa Charlin <teresa.charlinreyes@arm.com>
Mon, 1 Jul 2019 15:22:56 +0000 (16:22 +0100)
committerTeresa Charlin <teresa.charlinreyes@arm.com>
Mon, 1 Jul 2019 15:22:56 +0000 (16:22 +0100)
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Change-Id: Ibfd4725bb04a5859488e968513cf11ac450fd277

src/armnn/InternalTypes.cpp
src/armnn/QuantizerVisitor.cpp
src/armnn/QuantizerVisitor.hpp
src/armnn/StaticRangeVisitor.cpp
src/armnn/StaticRangeVisitor.hpp
src/armnn/test/QuantizerTest.cpp

index f62ce92..393e744 100644 (file)
@@ -51,6 +51,7 @@ char const* GetLayerTypeAsCString(LayerType type)
         case LayerType::PreCompiled: return "PreCompiled";
         case LayerType::Reshape: return "Reshape";
         case LayerType::Rsqrt: return "Rsqrt";
+        case LayerType::Resize: return "Resize";
         case LayerType::ResizeBilinear: return "ResizeBilinear";
         case LayerType::Softmax: return "Softmax";
         case LayerType::SpaceToBatchNd: return "SpaceToBatchNd";
index 292924c..f2e0506 100644 (file)
@@ -385,6 +385,15 @@ void QuantizerVisitor::VisitResizeBilinearLayer(const IConnectableLayer* layer,
     SetQuantizedInputConnections(layer, newLayer);
 }
 
+void QuantizerVisitor::VisitResizeLayer(const IConnectableLayer* layer,
+                                        const ResizeDescriptor& resizeDescriptor,
+                                        const char* name)
+{
+    IConnectableLayer* newLayer = m_QuantizedNetwork->AddResizeLayer(resizeDescriptor, name);
+    RecordLayer(layer, newLayer);
+    SetQuantizedInputConnections(layer, newLayer);
+}
+
 void QuantizerVisitor::VisitRsqrtLayer(const IConnectableLayer* layer,
                                        const char* name)
 {
index c3a2eaf..26158c3 100644 (file)
@@ -114,6 +114,10 @@ public:
                                   const ResizeBilinearDescriptor& resizeDesc,
                                   const char* name = nullptr) override;
 
+    void VisitResizeLayer(const IConnectableLayer* layer,
+                          const ResizeDescriptor& resizeDescriptor,
+                          const char* name = nullptr) override;
+
     void VisitRsqrtLayer(const IConnectableLayer*,
                          const char* name = nullptr) override;
 
index d437a99..94f0a01 100644 (file)
@@ -225,6 +225,15 @@ void StaticRangeVisitor::VisitResizeBilinearLayer(const IConnectableLayer* layer
     ForwardParentParameters(layer);
 }
 
+void StaticRangeVisitor::VisitResizeLayer(const IConnectableLayer* layer,
+                                          const ResizeDescriptor& resizeDescriptor,
+                                          const char* name)
+{
+    boost::ignore_unused(resizeDescriptor);
+    boost::ignore_unused(name);
+    ForwardParentParameters(layer);
+}
+
 void StaticRangeVisitor::VisitStridedSliceLayer(const IConnectableLayer* layer,
                                                 const StridedSliceDescriptor& stridedSliceDescriptor,
                                                 const char* name)
index a393a8e..37ebec8 100644 (file)
@@ -91,6 +91,10 @@ public:
                                   const ResizeBilinearDescriptor& resizeDesc,
                                   const char* name = nullptr) override;
 
+    void VisitResizeLayer(const IConnectableLayer* layer,
+                          const ResizeDescriptor& resizeDescriptor,
+                          const char* name = nullptr) override;
+
     void VisitStridedSliceLayer(const IConnectableLayer* layer,
                                 const StridedSliceDescriptor& stridedSliceDescriptor,
                                 const char* name = nullptr) override;
index 4732da3..57f602d 100644 (file)
@@ -1523,6 +1523,54 @@ BOOST_AUTO_TEST_CASE(QuantizeResizeBilinear)
     VisitLayersTopologically(quantizedNetworkQSymm16.get(), validatorQSymm16);
 }
 
+BOOST_AUTO_TEST_CASE(QuantizeResize)
+{
+    class TestResizeQuantization : public TestLeakyReLuActivationQuantization
+    {
+    public:
+        TestResizeQuantization(const TensorShape& inputShape, const TensorShape& outputShape)
+                : TestLeakyReLuActivationQuantization(inputShape, outputShape)
+        {}
+
+        TestResizeQuantization(const QuantizerOptions& options,
+                                       const TensorShape& inputShape,
+                                       const TensorShape& outputShape)
+                : TestLeakyReLuActivationQuantization(options, inputShape, outputShape)
+        {}
+
+        void VisitResizeLayer(const IConnectableLayer* layer,
+                                      const ResizeDescriptor& resizeDescriptor,
+                                      const char* name = nullptr) override
+        {
+            CheckForwardedQuantizationSettings(layer);
+        }
+    };
+
+    INetworkPtr network = INetwork::Create();
+
+    const TensorShape shape{1U};
+    TensorInfo info(shape, DataType::Float32);
+
+    IConnectableLayer* activation = CreateStartOfLeakyReluNetwork(network.get(), info);
+
+    // Add the layer under test
+    ResizeDescriptor descriptor;
+    descriptor.m_TargetHeight = 3;
+    descriptor.m_TargetWidth = 3;
+    IConnectableLayer* resizeLayer = network->AddResizeLayer(descriptor);
+
+    CompleteLeakyReluNetwork(network.get(), activation, resizeLayer, info);
+
+    INetworkPtr quantizedNetworkQAsymm8 = INetworkQuantizer::Create(network.get())->ExportNetwork();
+    TestResizeQuantization validatorQAsymm8(shape, shape);
+    VisitLayersTopologically(quantizedNetworkQAsymm8.get(), validatorQAsymm8);
+
+    const QuantizerOptions options(DataType::QuantisedSymm16);
+    INetworkPtr quantizedNetworkQSymm16 = INetworkQuantizer::Create(network.get(), options)->ExportNetwork();
+    TestResizeQuantization validatorQSymm16(options, shape, shape);
+    VisitLayersTopologically(quantizedNetworkQSymm16.get(), validatorQSymm16);
+}
+
 BOOST_AUTO_TEST_CASE(QuantizeStridedSlice)
 {
     class TestStridedSliceQuantization : public TestLeakyReLuActivationQuantization