aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan OShea <ryan.oshea3@arm.com>2023-07-28 17:35:18 +0100
committerryan.oshea3 <ryan.oshea3@arm.com>2023-08-02 13:33:28 +0000
commit083802d04b7a4499c4daba860c57e4f152f9c060 (patch)
treed1f51625f1d5046e6127235dceecdab6705bf0ec
parent7f2f59da45102cbb40df8d0a6b1159b787b96fde (diff)
downloadarmnn-083802d04b7a4499c4daba860c57e4f152f9c060.tar.gz
IVGCVSW-7703 Ensure PyArmNN has been updated with new features added in ArmNN
* Adds BatchMatMul layer and descriptor to pyarmnn * Adds ReverseV2 layer to pyarmnn * Adds ElementWiseBinary layer and descriptor to pyarmnn * Adds Tile layer and descriptor to pyarmnn * Adds network test for each layer Signed-off-by: Ryan OShea <ryan.oshea3@arm.com> Change-Id: Iac70fb7f857978d676d3b67a4cc20fb5f3270676
-rw-r--r--include/armnn/INetwork.hpp2
-rw-r--r--python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i136
-rw-r--r--python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i55
-rw-r--r--python/pyarmnn/test/test_network.py4
4 files changed, 196 insertions, 1 deletions
diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp
index 830e0bac66..1640d7c37d 100644
--- a/include/armnn/INetwork.hpp
+++ b/include/armnn/INetwork.hpp
@@ -435,7 +435,7 @@ public:
/// @param name - Optional name for the layer.
/// @param desc - Descriptor for the elementwiseBinary operations.
/// @return - Interface for configuring the layer.
- IConnectableLayer* AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor& elementwiseUnaryDescriptor,
+ IConnectableLayer* AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor& elementwiseBinaryDescriptor,
const char* name = nullptr);
/// Add an ElementwiseUnary layer to the network.
diff --git a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i
index 9374945daf..e755ef5982 100644
--- a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i
+++ b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_descriptors.i
@@ -91,6 +91,104 @@ struct ArgMinMaxDescriptor
%feature("docstring",
"
+ A descriptor for the BatchMatMul layer. See `INetwork.AddBatchMatMulLayer()`.
+
+ Contains:
+ m_TransposeX (bool): Transpose the slices of input tensor X. Transpose and Adjoint can not both be set to true for the same tensor at the same time.
+ m_TransposeY (bool): Transpose the slices of input tensor Y. Transpose and Adjoint can not both be set to true for the same tensor at the same time.
+ m_AdjointX (bool): Adjoint the slices of input tensor X. Transpose and Adjoint can not both be set to true for the same tensor at the same time.
+ m_AdjointY (bool): Adjoint the slices of input tensor Y. Transpose and Adjoint can not both be set to true for the same tensor at the same time.
+ m_DataLayoutX (DataLayout): Data layout of input tensor X, such as NHWC/NDHWC (leave as default for arbitrary layout).
+ m_DatalayoutY (DataLayout): Data layout of input tensor X, such as NHWC/NDHWC (leave as default for arbitrary layout)
+ ") BatchMatMulDescriptor;
+struct BatchMatMulDescriptor
+{
+ BatchMatMulDescriptor(bool transposeX = false,
+ bool transposeY = false,
+ bool adjointX = false,
+ bool adjointY = false,
+ DataLayout dataLayoutX = DataLayout::NCHW,
+ DataLayout dataLayoutY = DataLayout::NCHW)
+ : m_TransposeX(transposeX)
+ , m_TransposeY(transposeY)
+ , m_AdjointX(adjointX)
+ , m_AdjointY(adjointY)
+ , m_DataLayoutX(dataLayoutX)
+ , m_DataLayoutY(dataLayoutY)
+ {}
+
+ bool operator ==(const BatchMatMulDescriptor &rhs) const
+ {
+ return m_TransposeX == rhs.m_TransposeX &&
+ m_TransposeY == rhs.m_TransposeY &&
+ m_AdjointX == rhs.m_AdjointX &&
+ m_AdjointY == rhs.m_AdjointY &&
+ m_DataLayoutX == rhs.m_DataLayoutX &&
+ m_DataLayoutY == rhs.m_DataLayoutY;
+ }
+
+ bool m_TransposeX;
+ bool m_TransposeY;
+ bool m_AdjointX;
+ bool m_AdjointY;
+ DataLayout m_DataLayoutX;
+ DataLayout m_DataLayoutY;
+
+ static std::pair<std::pair<unsigned int, unsigned int>, std::pair<unsigned int, unsigned int>> GetAxesToMul(
+ const BatchMatMulDescriptor& desc,
+ const armnn::TensorShape& tensorXShape,
+ const armnn::TensorShape& tensorYShape);
+
+ static std::pair<std::vector<unsigned int>, std::vector<unsigned int>> GetAxesNotMul(
+ const BatchMatMulDescriptor& desc,
+ const armnn::TensorShape& inputXShape,
+ const armnn::TensorShape& inputYShape);
+
+ %feature("docstring",
+ "
+ Static helper to get the two axes (for each input) for multiplication
+ Args:
+ dataLayout (DataLayout)
+ tensorShape (TensorShape)
+
+ Returns:
+ std::pair<unsigned int, unsigned int>
+ ") GetAxesToMul;
+ static std::pair<unsigned int, unsigned int> GetAxesToMul(
+ DataLayout dataLayout,
+ const armnn::TensorShape& tensorShape);
+
+ %feature("docstring",
+ "
+ Static helper to get the two axes (for each input) that will not be multiplied together
+ Args:
+ dataLayout (DataLayout)
+ tensorShape (TensorShape)
+
+ Returns:
+ std::vector<unsigned int>
+ ") GetAxesToNotMul;
+ static std::vector<unsigned int> GetAxesNotMul(
+ DataLayout dataLayout,
+ const armnn::TensorShape& tensorShape);
+
+ %feature("docstring",
+ "
+ Static helper to get the axes which will be transposed
+ Args:
+ dataLayout (DataLayout)
+ tensorShape (TensorShape)
+
+ Returns:
+ PermutationVector
+ ") GetPermuteVec;
+ static PermutationVector GetPermuteVec(
+ DataLayout dataLayout,
+ const armnn::TensorShape& tensorShape);
+};
+
+%feature("docstring",
+ "
A descriptor for the BatchNormalization layer. See `INetwork.AddBatchNormalizationLayer()`.
Contains:
@@ -679,6 +777,26 @@ struct PadDescriptor
%feature("docstring",
"
+ A descriptor for the ElementwiseBinary layer. See `INetwork.AddElementwiseBinaryLayer()`.
+ Contains:
+ m_Operation (int): Indicates which Binary operation to use. (`BinaryOperation_Add`, `BinaryOperation_Div`,
+ `BinaryOperation_Maximum`, `BinaryOperation_Minimum`, `BinaryOperation_Mul`, `BinaryOperation_Sub`,
+ `BinaryOperation_SqDiff`, `BinaryOperation_Power`)
+ Default: `BinaryOperation_Add`.
+
+ ") ElementwiseBinaryDescriptor;
+struct ElementwiseBinaryDescriptor
+{
+ ElementwiseBinaryDescriptor();
+ ElementwiseBinaryDescriptor(BinaryOperation operation);
+
+ BinaryOperation m_Operation;
+
+ bool operator ==(const ElementwiseBinaryDescriptor &rhs) const;
+};
+
+%feature("docstring",
+ "
A descriptor for the ElementwiseUnary layer. See `INetwork.AddElementwiseUnaryLayer()`.
Contains:
@@ -1211,6 +1329,24 @@ struct LogicalBinaryDescriptor
%feature("docstring",
"
+ A descriptor for the Tile layer. See `INetwork.AddTileLayer()`.
+
+ Contains:
+ m_Multiples (std::vector<uint32_t>): The vector to multiply the input shape by
+
+ ") TileDescriptor;
+struct TileDescriptor
+{
+ TileDescriptor();
+ TileDescriptor(const std::vector<uint32_t>& multiples);
+
+ std::vector<uint32_t> m_Multiples;
+
+ bool operator ==(const TileDescriptor &rhs) const;
+};
+
+%feature("docstring",
+ "
A descriptor for the Transpose layer. See `INetwork.AddTransposeLayer()`.
Contains:
diff --git a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i
index c9eef8630d..0b7f55d1cc 100644
--- a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i
+++ b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_network.i
@@ -396,6 +396,21 @@ public:
%feature("docstring",
"
+ Adds a Batch Matrix Multiplication layer to the network.
+
+ Args:
+ desc (BatchMatMulDescriptor): Parameters for the BatchMatMul layer.
+ name (str): Optional name for the layer.
+
+ Returns:
+ IConnectableLayer: Interface for configuring the layer.
+ ") AddBatchMatMulLayer;
+ armnn::IConnectableLayer* AddBatchMatMulLayer(const armnn::BatchMatMulDescriptor& desc,
+ const char* name = nullptr);
+
+
+ %feature("docstring",
+ "
Adds a Batch Normalization layer to the network.
Args:
@@ -595,6 +610,20 @@ public:
%feature("docstring",
"
+ Adds an Elementwise Binary layer to the network. Type of binary operation to use is decided by elementwiseBinaryDescriptor. Binary operations supported are (Add, Div, Maximum, Minimum, Mul, Sub, SqDiff, Power)
+
+ Args:
+ elementwiseBinaryDescriptor (ElementwiseBinaryDescriptor): ElementwiseBinaryDescriptor to configure the choice of binary operation added to the network.
+ name (str): Optional name for the layer.
+
+ Returns:
+ IConnectableLayer: Interface for configuring the layer.
+ ") AddElementwiseBinaryLayer;
+ armnn::IConnectableLayer* AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor& elementwiseBinaryDescriptor,
+ const char* name = nullptr);
+
+ %feature("docstring",
+ "
Adds an Elementwise Unary layer to the network. Type of unary operation to use is decided by elementwiseUnaryDescriptor. Unary operations supported are (Abs, Exp, Neg, Rsqrt, Sqrt)
Args:
@@ -943,6 +972,18 @@ public:
%feature("docstring",
"
+ Adds a ReverseV2 layer to the network.
+
+ Args:
+ name (str): Optional name for the layer.
+
+ Returns:
+ IConnectableLayer: Interface for configuring the layer.
+ ") AddReverseV2Layer;
+ armnn::IConnectableLayer* AddReverseV2Layer(const char* name = nullptr);
+
+ %feature("docstring",
+ "
Adds a Shape layer to the network.
Args:
@@ -1122,6 +1163,20 @@ public:
%feature("docstring",
"
+ Adds a Tile layer to the network.
+
+ Args:
+ tileDescriptor (TileDescriptor): Description of the tile layer.
+ name (str): Optional name for the layer.
+
+ Returns:
+ IConnectableLayer: Interface for configuring the layer.
+ ") AddTileLayer;
+ armnn::IConnectableLayer* AddTileLayer(const armnn::TileDescriptor& tileDescriptor,
+ const char* name = nullptr);
+
+ %feature("docstring",
+ "
Adds a Transpose layer to the network.
Args:
diff --git a/python/pyarmnn/test/test_network.py b/python/pyarmnn/test/test_network.py
index 88be5a8e7f..91602b8fa8 100644
--- a/python/pyarmnn/test/test_network.py
+++ b/python/pyarmnn/test/test_network.py
@@ -190,6 +190,7 @@ def test_serialize_to_dot_mode_readonly(network_file, get_runtime, tmpdir):
'AddActivationLayer',
'AddAdditionLayer',
'AddArgMinMaxLayer',
+ 'AddBatchMatMulLayer',
'AddBatchNormalizationLayer',
'AddBatchToSpaceNdLayer',
'AddCastLayer',
@@ -204,6 +205,7 @@ def test_serialize_to_dot_mode_readonly(network_file, get_runtime, tmpdir):
'AddDequantizeLayer',
'AddDetectionPostProcessLayer',
'AddDivisionLayer',
+ 'AddElementwiseBinaryLayer',
'AddElementwiseUnaryLayer',
'AddFloorLayer',
'AddFillLayer',
@@ -234,6 +236,7 @@ def test_serialize_to_dot_mode_readonly(network_file, get_runtime, tmpdir):
'AddReduceLayer',
'AddReshapeLayer',
'AddResizeLayer',
+ 'AddReverseV2Layer',
'AddShapeLayer',
'AddSliceLayer',
'AddSoftmaxLayer',
@@ -245,6 +248,7 @@ def test_serialize_to_dot_mode_readonly(network_file, get_runtime, tmpdir):
'AddStridedSliceLayer',
'AddSubtractionLayer',
'AddSwitchLayer',
+ 'AddTileLayer',
'AddTransposeConvolution2dLayer',
'AddTransposeLayer'
])