From ce5045a00485f8a8c35814c0781ccbcca5678e5c Mon Sep 17 00:00:00 2001 From: Kevin May Date: Wed, 2 Oct 2019 14:07:47 +0100 Subject: IVGCVSW-3932 Add frontend for INSTANCE_NORMALIZATION Signed-off-by: Kevin May Change-Id: Ib152148ccd8d2733c617d0cf9402661fc6b71316 --- include/armnn/Descriptors.hpp | 20 ++++++++++++++++++++ include/armnn/DescriptorsFwd.hpp | 1 + include/armnn/ILayerSupport.hpp | 6 ++++++ include/armnn/ILayerVisitor.hpp | 8 ++++++++ include/armnn/INetwork.hpp | 7 +++++++ include/armnn/LayerVisitorBase.hpp | 4 ++++ 6 files changed, 46 insertions(+) (limited to 'include') diff --git a/include/armnn/Descriptors.hpp b/include/armnn/Descriptors.hpp index c973089df6..5bf4043afa 100644 --- a/include/armnn/Descriptors.hpp +++ b/include/armnn/Descriptors.hpp @@ -468,6 +468,26 @@ struct BatchNormalizationDescriptor DataLayout m_DataLayout; }; +/// An InstanceNormalizationDescriptor for InstanceNormalizationLayer +struct InstanceNormalizationDescriptor +{ + InstanceNormalizationDescriptor() + : m_Gamma(1.0f) + , m_Beta(0.0f) + , m_Eps(1e-12f) + , m_DataLayout(DataLayout::NCHW) + {} + + /// Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. + float m_Gamma; + /// Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0. + float m_Beta; + /// Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f. + float m_Eps; + /// The data layout to be used (NCHW, NHWC). + DataLayout m_DataLayout; +}; + /// A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer. struct BatchToSpaceNdDescriptor { diff --git a/include/armnn/DescriptorsFwd.hpp b/include/armnn/DescriptorsFwd.hpp index e9624f18ce..2cc95828e6 100644 --- a/include/armnn/DescriptorsFwd.hpp +++ b/include/armnn/DescriptorsFwd.hpp @@ -16,6 +16,7 @@ struct DepthwiseConvolution2dDescriptor; struct DetectionPostProcessDescriptor; struct FakeQuantizationDescriptor; struct FullyConnectedDescriptor; +struct InstanceNormalizationDescriptor; struct L2NormalizationDescriptor; struct LstmDescriptor; struct MeanDescriptor; diff --git a/include/armnn/ILayerSupport.hpp b/include/armnn/ILayerSupport.hpp index e18b86acfd..fef7595b54 100644 --- a/include/armnn/ILayerSupport.hpp +++ b/include/armnn/ILayerSupport.hpp @@ -157,6 +157,12 @@ public: virtual bool IsInputSupported(const TensorInfo& input, Optional reasonIfUnsupported = EmptyOptional()) const = 0; + virtual bool IsInstanceNormalizationSupported( + const TensorInfo& input, + const TensorInfo& output, + const InstanceNormalizationDescriptor& descriptor, + Optional reasonIfUnsupported = EmptyOptional()) const = 0; + virtual bool IsL2NormalizationSupported(const TensorInfo& input, const TensorInfo& output, const L2NormalizationDescriptor& descriptor, diff --git a/include/armnn/ILayerVisitor.hpp b/include/armnn/ILayerVisitor.hpp index 486a13f847..b9c96d5448 100644 --- a/include/armnn/ILayerVisitor.hpp +++ b/include/armnn/ILayerVisitor.hpp @@ -206,6 +206,14 @@ public: LayerBindingId id, const char* name = nullptr) = 0; + /// Function that an instance normalization layer should call back to when its Accept(ILayerVisitor&) + /// function is invoked. + /// @param layer - pointer to the layer which is calling back to this visit function. + /// @param desc - Parameters for the instance normalization operation. + /// @param name - Optional name for the layer. + virtual void VisitInstanceNormalizationLayer(const IConnectableLayer* layer, + const InstanceNormalizationDescriptor& desc, + const char* name = nullptr) = 0; /// Function that an L2 normalization layer should call back to when its Accept(ILayerVisitor&) /// function is invoked. Normalization is performed along dimension 1, but requires a 4d input. diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp index 0e0b99a718..dc831db864 100644 --- a/include/armnn/INetwork.hpp +++ b/include/armnn/INetwork.hpp @@ -329,6 +329,13 @@ public: virtual IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor, const char* name = nullptr) = 0; + /// Adds an instance normalization layer to the network. + /// @param desc - Parameters for the instance normalization operation. + /// @param name - Optional name for the layer. + /// @return - Interface for configuring the layer. + virtual IConnectableLayer* AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor& desc, + const char* name = nullptr) = 0; + /// Adds an L2 normalization layer to the network. /// Normalization is performed along dimension 1, but requires a 4d input. /// @param desc - Parameters for the L2 normalization operation. diff --git a/include/armnn/LayerVisitorBase.hpp b/include/armnn/LayerVisitorBase.hpp index 65d23039b7..719e59d39c 100644 --- a/include/armnn/LayerVisitorBase.hpp +++ b/include/armnn/LayerVisitorBase.hpp @@ -112,6 +112,10 @@ public: LayerBindingId, const char*) override { DefaultPolicy::Apply(__func__); } + void VisitInstanceNormalizationLayer(const IConnectableLayer*, + const InstanceNormalizationDescriptor&, + const char*) override { DefaultPolicy::Apply(__func__); } + void VisitL2NormalizationLayer(const IConnectableLayer*, const L2NormalizationDescriptor&, const char*) override { DefaultPolicy::Apply(__func__); } -- cgit v1.2.1