From 89655004ba20d36ec4882ed9c10f5d91aa244af2 Mon Sep 17 00:00:00 2001 From: Ryan OShea Date: Wed, 9 Mar 2022 02:07:24 +0000 Subject: IVGCVSW-6749 Add Pooling3d to PyArmnn * Add layer to __init__.py * Add descriptor for Pooling3d * Add descriptor test for Pooling3d * Add network test for Pooling3d layer Signed-off-by: Ryan OShea Change-Id: Id5e1587a89d3ffb5bee7764a92b299fa43a2ae35 --- python/pyarmnn/src/pyarmnn/__init__.py | 2 +- .../src/pyarmnn/swig/modules/armnn_descriptors.i | 47 ++++++++++++++++++++++ .../src/pyarmnn/swig/modules/armnn_network.i | 16 +++++++- python/pyarmnn/test/test_descriptors.py | 18 +++++++++ python/pyarmnn/test/test_network.py | 1 + 5 files changed, 82 insertions(+), 2 deletions(-) diff --git a/python/pyarmnn/src/pyarmnn/__init__.py b/python/pyarmnn/src/pyarmnn/__init__.py index b994bb7bb7..4e8401cdd4 100644 --- a/python/pyarmnn/src/pyarmnn/__init__.py +++ b/python/pyarmnn/src/pyarmnn/__init__.py @@ -96,7 +96,7 @@ from ._generated.pyarmnn import PaddingMode_Constant, PaddingMode_Reflect, Paddi from ._generated.pyarmnn import PermutationVector, PermuteDescriptor from ._generated.pyarmnn import OutputShapeRounding_Ceiling, OutputShapeRounding_Floor, \ PaddingMethod_Exclude, PaddingMethod_IgnoreValue, PoolingAlgorithm_Average, PoolingAlgorithm_L2, \ - PoolingAlgorithm_Max, Pooling2dDescriptor + PoolingAlgorithm_Max, Pooling2dDescriptor, Pooling3dDescriptor from ._generated.pyarmnn import ReduceDescriptor, ReduceOperation_Prod, ReduceOperation_Max, ReduceOperation_Mean, \ ReduceOperation_Min, ReduceOperation_Sum from ._generated.pyarmnn import ResizeMethod_Bilinear, ResizeMethod_NearestNeighbor, ResizeDescriptor, \ diff --git a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i index 733002318d..c64fef3d4f 100644 --- a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i +++ b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i @@ -743,6 +743,53 @@ struct Pooling2dDescriptor bool operator ==(const Pooling2dDescriptor& rhs) const; }; +%feature("docstring", + " + A descriptor for the Pooling3d layer. See `INetwork.AddPooling3dLayer()`. + + Contains: + m_PoolType (int): The pooling algorithm to use (`PoolingAlgorithm_Max`, `PoolingAlgorithm_Average`, `PoolingAlgorithm_L2`). Default: `PoolingAlgorithm_Max`. + m_PadLeft (int): Underlying C++ data type is uint32_t. Padding left value in the width dimension. Default: 0. + m_PadRight (int): Underlying C++ data type is uint32_t. Padding right value in the width dimension. Default: 0. + m_PadTop (int): Underlying C++ data type is uint32_t. Padding top value in the height dimension. Default: 0. + m_PadBottom (int): Underlying C++ data type is uint32_t. Padding bottom value in the height dimension. Default: 0. + m_PadFront (int): Underlying C++ data type is uint32_t. Padding front value in the depth dimension. Default: 0. + m_PadBack (int): Underlying C++ data type is uint32_t. Padding back value in the depth dimension. Default: 0. + m_PoolWidth (int): Underlying C++ data type is uint32_t. Pooling width value. Default: 0. + m_PoolHeight (int): Underlying C++ data type is uint32_t. Pooling height value. Default: 0. + m_StrideX (int): Underlying C++ data type is uint32_t. Stride value when proceeding through input for the width dimension. Default: 0. + m_StrideY (int): Underlying C++ data type is uint32_t. Stride value when proceeding through input for the height dimension. Default: 0. + m_StrideZ (int): Underlying C++ data type is uint32_t. Stride value when proceeding through input for the depth dimension. Default: 0. + m_OutputShapeRounding (int): The rounding method for the output shape. (`OutputShapeRounding_Floor`, `OutputShapeRounding_Ceiling`). + Default: `OutputShapeRounding_Floor`. + m_PaddingMethod (int): The padding method to be used. (`PaddingMethod_Exclude`, `PaddingMethod_IgnoreValue`). + Default: `PaddingMethod_Exclude`. + m_DataLayout (int): The data layout to be used (`DataLayout_NCDHW`, `DataLayout_NDHWC`). Default: `DataLayout_NCDHW`. + + ") Pooling3dDescriptor; +struct Pooling3dDescriptor +{ + Pooling3dDescriptor(); + + PoolingAlgorithm m_PoolType; + uint32_t m_PadLeft; + uint32_t m_PadRight; + uint32_t m_PadTop; + uint32_t m_PadBottom; + uint32_t m_PadFront; + uint32_t m_PadBack; + uint32_t m_PoolWidth; + uint32_t m_PoolHeight; + uint32_t m_StrideX; + uint32_t m_StrideY; + uint32_t m_StrideZ; + OutputShapeRounding m_OutputShapeRounding; + PaddingMethod m_PaddingMethod; + DataLayout m_DataLayout; + + bool operator ==(const Pooling3dDescriptor& rhs) const; +}; + %feature("docstring", " A ReduceDescriptor for the REDUCE operators. diff --git a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i index eb8dede260..1957288003 100644 --- a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i +++ b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i @@ -803,7 +803,21 @@ public: IConnectableLayer: Interface for configuring the layer. ") AddPooling2dLayer; armnn::IConnectableLayer* AddPooling2dLayer(const armnn::Pooling2dDescriptor& pooling2dDescriptor, - const char* name = nullptr); + const char* name = nullptr); + + %feature("docstring", + " + Adds a 3D Pooling layer to the network. Type of 3D pooling is decided by the configuration. + + Args: + pooling3dDescriptor (Pooling3dDescriptor): Configuration for the 3D pooling layer. + name (str): Optional name for the layer. + + Returns: + IConnectableLayer: Interface for configuring the layer. + ") AddPooling3dLayer; + armnn::IConnectableLayer* AddPooling3dLayer(const armnn::Pooling3dDescriptor& pooling3dDescriptor, + const char* name = nullptr); %feature("docstring", " diff --git a/python/pyarmnn/test/test_descriptors.py b/python/pyarmnn/test/test_descriptors.py index 262b8fcf2a..8969344d6d 100644 --- a/python/pyarmnn/test/test_descriptors.py +++ b/python/pyarmnn/test/test_descriptors.py @@ -282,6 +282,24 @@ def test_pooling_descriptor_default_values(): assert desc.m_PaddingMethod == ann.PaddingMethod_Exclude assert desc.m_DataLayout == ann.DataLayout_NCHW +def test_pooling_3d_descriptor_default_values(): + desc = ann.Pooling3dDescriptor() + assert desc.m_PoolType == ann.PoolingAlgorithm_Max + assert desc.m_PadLeft == 0 + assert desc.m_PadTop == 0 + assert desc.m_PadRight == 0 + assert desc.m_PadBottom == 0 + assert desc.m_PadFront == 0 + assert desc.m_PadBack == 0 + assert desc.m_PoolHeight == 0 + assert desc.m_PoolWidth == 0 + assert desc.m_StrideX == 0 + assert desc.m_StrideY == 0 + assert desc.m_StrideZ == 0 + assert desc.m_OutputShapeRounding == ann.OutputShapeRounding_Floor + assert desc.m_PaddingMethod == ann.PaddingMethod_Exclude + assert desc.m_DataLayout == ann.DataLayout_NCDHW + def test_reshape_descriptor_default_values(): desc = ann.ReshapeDescriptor() diff --git a/python/pyarmnn/test/test_network.py b/python/pyarmnn/test/test_network.py index 27ad70be3b..8cb81221e2 100644 --- a/python/pyarmnn/test/test_network.py +++ b/python/pyarmnn/test/test_network.py @@ -225,6 +225,7 @@ def test_serialize_to_dot_mode_readonly(network_file, get_runtime, tmpdir): 'AddPadLayer', 'AddPermuteLayer', 'AddPooling2dLayer', + 'AddPooling3dLayer', 'AddPreluLayer', 'AddQuantizeLayer', 'AddQuantizedLstmLayer', -- cgit v1.2.1