ArmNN
 25.11
Loading...
Searching...
No Matches
TransposeConvolution2dLayer Class Reference

This layer represents a 2D transpose convolution operation. More...

#include <TransposeConvolution2dLayer.hpp>

Inheritance diagram for TransposeConvolution2dLayer:
[legend]
Collaboration diagram for TransposeConvolution2dLayer:
[legend]

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the TransposeConvolution2d type.
TransposeConvolution2dLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer.
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of TransposeConvolution2dLayer.
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 Infers the output shapes from given input shapes and layer properties.
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
Public Member Functions inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
const TransposeConvolution2dDescriptorGetParameters () const override
 If the layer has a descriptor return it.
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
const std::string & GetNameStr () const
const OutputHandlerGetOutputHandler (unsigned int i=0) const
OutputHandlerGetOutputHandler (unsigned int i=0)
ShapeInferenceMethod GetShapeInferenceMethod () const
bool GetAllowExpandedDims () const
const std::vector< InputSlot > & GetInputSlots () const
const std::vector< OutputSlot > & GetOutputSlots () const
std::vector< InputSlot >::iterator BeginInputSlots ()
std::vector< InputSlot >::iterator EndInputSlots ()
std::vector< OutputSlot >::iterator BeginOutputSlots ()
std::vector< OutputSlot >::iterator EndOutputSlots ()
bool IsOutputUnconnected ()
void ResetPriority () const
LayerPriority GetPriority () const
LayerType GetType () const override
 Returns the armnn::LayerType of this layer.
DataType GetDataType () const
const BackendIdGetBackendId () const
void SetBackendId (const BackendId &id) override
 Set the backend of the IConnectableLayer.
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
virtual void ReleaseConstantData ()
template<typename Op>
void OperateOnConstantTensors (Op op)
const char * GetName () const override
 Returns the name of the layer.
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots.
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots.
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index.
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index.
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index.
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index.
void SetGuid (LayerGuid guid)
LayerGuid GetGuid () const final
 Returns the unique id of the layer.
void AddRelatedLayerName (const std::string layerName)
const std::list< std::string > & GetRelatedLayerNames ()
virtual void Reparent (Graph &dest, std::list< Layer * >::const_iterator iterator)=0
void BackendSelectionHint (Optional< BackendId > backend) final
 Provide a hint for the optimizer as to which backend to prefer for this layer.
Optional< BackendIdGetBackendHint () const
void SetShapeInferenceMethod (ShapeInferenceMethod shapeInferenceMethod)
void SetAllowExpandedDims (bool allowExpandedDims)
template<typename T>
std::shared_ptr< T > GetAdditionalInformation () const
void SetAdditionalInfoForObject (const AdditionalInfoObjectPtr &additionalInfo)

Public Attributes

std::shared_ptr< ConstTensorHandlem_Weight
 A unique pointer to store weight values.
std::shared_ptr< ConstTensorHandlem_Bias
 A unique pointer to store bias values.

Protected Member Functions

 TransposeConvolution2dLayer (const TransposeConvolution2dDescriptor &param, const char *name)
 Constructor to create a TransposeConvolution2dLayer.
 ~TransposeConvolution2dLayer ()=default
 Default destructor.
ImmutableConstantTensors GetConstantTensorsByRef () const override
 Retrieve the handles to the constant values stored by the layer.
Protected Member Functions inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
 LayerWithParameters (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const TransposeConvolution2dDescriptor &param, const char *name)
 ~LayerWithParameters ()=default
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors () const
Protected Member Functions inherited from Layer
virtual ~Layer ()=default
template<typename QueueDescriptor>
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
template<typename QueueDescriptor>
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
void ValidateAndCopyShape (const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void VerifyShapeInferenceType (const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
template<typename QueueDescriptor>
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
template<typename LayerType, typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
virtual ConstantTensors GetConstantTensorsByRef () override final
void SetAdditionalInfo (QueueDescriptor &descriptor) const
Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle.

Additional Inherited Members

Public Types inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
using DescriptorType
Public Types inherited from IConnectableLayer
using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>
using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>
Protected Attributes inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
TransposeConvolution2dDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.).
Protected Attributes inherited from Layer
AdditionalInfoObjectPtr m_AdditionalInfoObject
std::vector< OutputHandlerm_OutputHandlers
ShapeInferenceMethod m_ShapeInferenceMethod

Detailed Description

This layer represents a 2D transpose convolution operation.

Definition at line 15 of file TransposeConvolution2dLayer.hpp.

Constructor & Destructor Documentation

◆ TransposeConvolution2dLayer()

TransposeConvolution2dLayer ( const TransposeConvolution2dDescriptor & param,
const char * name )
protected

Constructor to create a TransposeConvolution2dLayer.

Parameters
[in]paramTransposeConvolution2dDescriptor to configure the 2D transpose convolution operation.
[in]nameOptional name for the layer.

Definition at line 19 of file TransposeConvolution2dLayer.cpp.

22{
23}
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const TransposeConvolution2dDescriptor &param, const char *name)

References LayerWithParameters< TransposeConvolution2dDescriptor >::LayerWithParameters(), and armnn::TransposeConvolution2d.

Referenced by Clone().

◆ ~TransposeConvolution2dLayer()

~TransposeConvolution2dLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Clone()

TransposeConvolution2dLayer * Clone ( Graph & graph) const
overridevirtual

Creates a dynamically-allocated copy of this layer.

Parameters
[in]graphThe graph into which this layer is being cloned.

Implements Layer.

Definition at line 49 of file TransposeConvolution2dLayer.cpp.

50{
52
53 layer->m_Weight = m_Weight ? m_Weight : nullptr;
54
55 if (layer->m_Param.m_BiasEnabled)
56 {
57 layer->m_Bias = m_Bias ? m_Bias : nullptr;
58 }
59
60 return std::move(layer);
61}
LayerType * CloneBase(Graph &graph, Params &&... params) const
const char * GetName() const override
Returns the name of the layer.
Definition Layer.hpp:332
std::shared_ptr< ConstTensorHandle > m_Weight
A unique pointer to store weight values.
std::shared_ptr< ConstTensorHandle > m_Bias
A unique pointer to store bias values.

References Layer::CloneBase(), Layer::GetName(), m_Bias, LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, m_Weight, and TransposeConvolution2dLayer().

◆ CreateWorkload()

std::unique_ptr< IWorkload > CreateWorkload ( const IWorkloadFactory & factory) const
overridevirtual

Makes a workload for the TransposeConvolution2d type.

Parameters
[in]graphThe graph where this layer can be found.
[in]factoryThe workload factory which will create the workload.
Returns
A pointer to the created workload, or nullptr if not created.

Implements Layer.

Definition at line 25 of file TransposeConvolution2dLayer.cpp.

26{
27 if (!m_Weight)
28 {
29 throw armnn::NullPointerException("TransposeConvolution2dLayer: Weights data should not be null.");
30 }
31
32 TransposeConvolution2dQueueDescriptor descriptor;
33 descriptor.m_Weight = m_Weight.get();
34
36 {
37 if (!m_Bias)
38 {
39 throw armnn::NullPointerException("TransposeConvolution2dLayer: Bias data should not be null.");
40 }
41 descriptor.m_Bias = m_Bias.get();
42 }
43
44 SetAdditionalInfo(descriptor);
45
46 return factory.CreateWorkload(LayerType::TransposeConvolution2d, descriptor, PrepInfoAndDesc(descriptor));
47}
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const =0
Backends should implement their own CreateWorkload function with a switch statement.
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition Layer.cpp:303
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const

References IWorkloadFactory::CreateWorkload(), m_Bias, TransposeConvolution2dQueueDescriptor::m_Bias, LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, m_Weight, TransposeConvolution2dQueueDescriptor::m_Weight, LayerWithParameters< TransposeConvolution2dDescriptor >::PrepInfoAndDesc(), Layer::SetAdditionalInfo(), and armnn::TransposeConvolution2d.

◆ ExecuteStrategy()

void ExecuteStrategy ( IStrategy & strategy) const
overridevirtual

Apply a visitor to this layer.

Reimplemented from LayerWithParameters< TransposeConvolution2dDescriptor >.

Definition at line 161 of file TransposeConvolution2dLayer.cpp.

162{
163 ManagedConstTensorHandle managedWeight(m_Weight);
164 std::vector<armnn::ConstTensor> constTensors { { managedWeight.GetTensorInfo(), managedWeight.Map() } };
165
166 ManagedConstTensorHandle managedBias(m_Bias);
167 if (GetParameters().m_BiasEnabled)
168 {
169 constTensors.emplace_back(ConstTensor(managedBias.GetTensorInfo(), managedBias.Map()));
170 }
171
172 strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
173}
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
const TransposeConvolution2dDescriptor & GetParameters() const override

References IStrategy::ExecuteStrategy(), Layer::GetName(), LayerWithParameters< TransposeConvolution2dDescriptor >::GetParameters(), ManagedConstTensorHandle::GetTensorInfo(), m_Bias, m_Weight, and ManagedConstTensorHandle::Map().

◆ GetConstantTensorsByRef()

Layer::ImmutableConstantTensors GetConstantTensorsByRef ( ) const
overrideprotectedvirtual

Retrieve the handles to the constant values stored by the layer.

Returns
A vector of the constant tensors stored by this layer.

Reimplemented from Layer.

Definition at line 155 of file TransposeConvolution2dLayer.cpp.

156{
157 // For API stability DO NOT ALTER order and add new members to the end of vector
158 return {m_Weight, m_Bias};
159}

References m_Bias, and m_Weight.

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > & inputShapes) const
overridevirtual

Infers the output shapes from given input shapes and layer properties.

Parameters
[in]inputShapesThe input shapes the layer has.
Returns
A vector of the inferred output shape.

Reimplemented from Layer.

Definition at line 63 of file TransposeConvolution2dLayer.cpp.

65{
66 if (inputShapes.size() != 2)
67 {
68 throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
69 "\" - should be \"2\".");
70 }
71
72 const TensorShape& inputShape = inputShapes[0];
73 const TensorShape& kernelShape = inputShapes[1];
74
75 if (inputShape.GetNumDimensions() != 4)
76 {
77 throw armnn::Exception("Transpose convolutions will always have 4D input");
78 }
79
80 DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
81
82 const unsigned int batches = inputShape[0];
83
84 const unsigned int wInput = inputShape[dataLayoutIndex.GetWidthIndex()];
85 const unsigned int hInput = inputShape[dataLayoutIndex.GetHeightIndex()];
86
87 const unsigned int wKernel = kernelShape[dataLayoutIndex.GetWidthIndex()];
88 const unsigned int hKernel = kernelShape[dataLayoutIndex.GetHeightIndex()];
89
90 unsigned int wPadding = m_Param.m_PadLeft + m_Param.m_PadRight;
91 unsigned int hPadding = m_Param.m_PadTop + m_Param.m_PadBottom;
92
93 unsigned int wOutput = (wInput - 1) * m_Param.m_StrideX + wKernel - wPadding;
94 unsigned int hOutput = (hInput - 1) * m_Param.m_StrideY + hKernel - hPadding;
95 unsigned int cOutput = kernelShape[0];
96
97 TensorShape tensorShape = m_Param.m_DataLayout == armnn::DataLayout::NHWC ?
98 TensorShape( { batches, hOutput, wOutput, cOutput } ) :
99 TensorShape( { batches, cOutput, hOutput, wOutput });
100
101 return std::vector<TensorShape>({ tensorShape });
102}
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition Tensor.cpp:174
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.

References DataLayoutIndexed::GetHeightIndex(), TensorShape::GetNumDimensions(), DataLayoutIndexed::GetWidthIndex(), LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, and armnn::NHWC.

Referenced by ValidateTensorShapesFromInputs().

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of TransposeConvolution2dLayer.

Parameters
[in]shapeInferenceMethodIndicates if output shape shall be overwritten or just validated.

Implements Layer.

Definition at line 104 of file TransposeConvolution2dLayer.cpp.

105{
107
108 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
109
111
112 if (!m_Weight)
113 {
114 throw armnn::LayerValidationException("TransposeConvolution2dLayer: Weight data cannot be null.");
115 }
116
117 std::vector<TensorShape> expectedOutputShape;
118 std::vector<TensorShape> outputShapeGivenAsInput;
119
120 expectedOutputShape = InferOutputShapes({GetInputSlot(0).GetTensorInfo().GetShape(),
121 m_Weight->GetTensorInfo().GetShape() });
122
123 if (expectedOutputShape.size() != 1)
124 {
125 throw armnn::LayerValidationException("expectedOutputShape' size is "
126 + std::to_string(expectedOutputShape.size()) +
127 " - should be \"1\".");
128 }
129
130 // If output_shape was specified then use it rather than calculate an inferred output shape.
132 {
133 TensorShape shapeAsTensorShape(static_cast<unsigned int>(m_Param.m_OutputShape.size()),
134 m_Param.m_OutputShape.data());
135 outputShapeGivenAsInput.push_back(shapeAsTensorShape);
136
137 if (outputShapeGivenAsInput.size() != 1)
138 {
139 throw armnn::LayerValidationException("outputShapeGivenAsInput' size is "
140 + std::to_string(outputShapeGivenAsInput.size()) +
141 " - should be \"1\".");
142 }
143
144 if (expectedOutputShape != outputShapeGivenAsInput)
145 {
146 throw armnn::LayerValidationException("TransposeConvolution2dLayer: "
147 "output calculated by InferOutputShapes and the output given "
148 "as an input parameter to the layer are not matching");
149 }
150 }
151
152 ValidateAndCopyShape(outputShape, expectedOutputShape[0], m_ShapeInferenceMethod, "TransposeConvolution2dLayer");
153}
#define CHECK_LOCATION()
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition Layer.cpp:614
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition Layer.cpp:410
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition Layer.cpp:526
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition Layer.hpp:339
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition Layer.cpp:457
ShapeInferenceMethod m_ShapeInferenceMethod
Definition Layer.hpp:441
const TensorInfo & GetTensorInfo() const override
Definition Layer.cpp:100
const TensorShape & GetShape() const
Definition Tensor.hpp:193
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infers the output shapes from given input shapes and layer properties.
std::vector< unsigned int > m_OutputShape
bool m_OutputShapeEnabled
Output shape if it has been specified.

References CHECK_LOCATION, Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), InferOutputShapes(), LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, Layer::m_ShapeInferenceMethod, m_Weight, Layer::ValidateAndCopyShape(), Layer::VerifyLayerConnections(), and Layer::VerifyShapeInferenceType().

Member Data Documentation

◆ m_Bias

std::shared_ptr<ConstTensorHandle> m_Bias

A unique pointer to store bias values.

Definition at line 21 of file TransposeConvolution2dLayer.hpp.

Referenced by Clone(), CreateWorkload(), ExecuteStrategy(), and GetConstantTensorsByRef().

◆ m_Weight

std::shared_ptr<ConstTensorHandle> m_Weight

The documentation for this class was generated from the following files: