ArmNN  NotReleased
TransposeConvolution2dLayer Class Reference

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

#include <TransposeConvolution2dLayer.hpp>

Inheritance diagram for TransposeConvolution2dLayer:
LayerWithParameters< TransposeConvolution2dDescriptor > Layer IConnectableLayer

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 
TransposeConvolution2dLayerClone (Graph &graph) const override
 
void ValidateTensorShapesFromInputs () override
 
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 
void Accept (ILayerVisitor &visitor) const override
 
- Public Member Functions inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
const TransposeConvolution2dDescriptorGetParameters () const
 
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 
- 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)
 
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
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
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
 
unsigned int GetNumInputSlots () const override
 
unsigned int GetNumOutputSlots () const override
 
const InputSlotGetInputSlot (unsigned int index) const override
 
InputSlotGetInputSlot (unsigned int index) override
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 

Public Attributes

std::unique_ptr< ScopedCpuTensorHandlem_Weight
 A unique pointer to store weight values. More...
 
std::unique_ptr< ScopedCpuTensorHandlem_Bias
 A unique pointer to store bias values. More...
 

Protected Member Functions

 TransposeConvolution2dLayer (const TransposeConvolution2dDescriptor &param, const char *name)
 
 ~TransposeConvolution2dLayer ()=default
 Default destructor. More...
 
ConstantTensors GetConstantTensorsByRef () override
 
- 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. More...
 
- 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
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Additional Inherited Members

- Public Types inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
using DescriptorType = TransposeConvolution2dDescriptor
 
- Protected Types inherited from Layer
using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 
- Protected Attributes inherited from LayerWithParameters< TransposeConvolution2dDescriptor >
TransposeConvolution2dDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.). More...
 
- Protected Attributes inherited from Layer
std::vector< OutputHandlerm_OutputHandlers
 

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 21 of file TransposeConvolution2dLayer.cpp.

References armnn::TransposeConvolution2d.

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

◆ ~TransposeConvolution2dLayer()

~TransposeConvolution2dLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Accept()

void Accept ( ILayerVisitor visitor) const
overridevirtual

Implements IConnectableLayer.

Definition at line 120 of file TransposeConvolution2dLayer.cpp.

References Layer::GetName(), LayerWithParameters< TransposeConvolution2dDescriptor >::GetParameters(), TransposeConvolution2dLayer::m_Bias, TransposeConvolution2dLayer::m_Weight, and ILayerVisitor::VisitTransposeConvolution2dLayer().

121 {
122  ConstTensor weightsTensor(m_Weight->GetTensorInfo(), m_Weight->Map(true)) ;
123  Optional<ConstTensor> optionalBiasTensor = EmptyOptional();
124 
125  if (GetParameters().m_BiasEnabled)
126  {
127  ConstTensor biasTensor(m_Bias->GetTensorInfo(), m_Bias->Map(true));
128  optionalBiasTensor = Optional<ConstTensor>(biasTensor);
129  }
130 
131  visitor.VisitTransposeConvolution2dLayer(this, GetParameters(), weightsTensor, optionalBiasTensor, GetName());
132 }
const char * GetName() const override
Definition: Layer.hpp:305
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:199
const TransposeConvolution2dDescriptor & GetParameters() const
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store bias values.
virtual void VisitTransposeConvolution2dLayer(const IConnectableLayer *layer, const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)=0
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.

◆ 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 43 of file TransposeConvolution2dLayer.cpp.

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

44 {
45  auto layer = CloneBase<TransposeConvolution2dLayer>(graph, m_Param, GetName());
46 
47  layer->m_Weight = m_Weight ? std::make_unique<ScopedCpuTensorHandle>(*m_Weight) : nullptr;
48 
49  if (layer->m_Param.m_BiasEnabled)
50  {
51  layer->m_Bias = m_Bias ? std::make_unique<ScopedCpuTensorHandle>(*m_Bias) : nullptr;
52  }
53 
54  return std::move(layer);
55 }
const char * GetName() const override
Definition: Layer.hpp:305
TransposeConvolution2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store bias values.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.

◆ 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 27 of file TransposeConvolution2dLayer.cpp.

References IWorkloadFactory::CreateTransposeConvolution2d(), TransposeConvolution2dLayer::m_Bias, TransposeConvolution2dQueueDescriptor::m_Bias, TransposeConvolution2dDescriptor::m_BiasEnabled, LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, TransposeConvolution2dLayer::m_Weight, TransposeConvolution2dQueueDescriptor::m_Weight, and LayerWithParameters< TransposeConvolution2dDescriptor >::PrepInfoAndDesc().

28 {
29  BOOST_ASSERT_MSG(m_Weight != nullptr, "TransposeConvolution2dLayer: Weights data should not be null.");
30 
32  descriptor.m_Weight = m_Weight.get();
33 
35  {
36  BOOST_ASSERT_MSG(m_Bias != nullptr, "TransposeConvolution2dLayer: Bias data should not be null.");
37  descriptor.m_Bias = m_Bias.get();
38  }
39 
40  return factory.CreateTransposeConvolution2d(descriptor, PrepInfoAndDesc(descriptor));
41 }
TransposeConvolution2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store bias values.
bool m_BiasEnabled
Enable/disable bias.
virtual std::unique_ptr< IWorkload > CreateTransposeConvolution2d(const TransposeConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info) const
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.

◆ GetConstantTensorsByRef()

Layer::ConstantTensors GetConstantTensorsByRef ( )
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 115 of file TransposeConvolution2dLayer.cpp.

References TransposeConvolution2dLayer::m_Bias, and TransposeConvolution2dLayer::m_Weight.

116 {
117  return {m_Weight, m_Bias};
118 }
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store bias values.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.

◆ 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 57 of file TransposeConvolution2dLayer.cpp.

References TransposeConvolution2dDescriptor::m_DataLayout, TransposeConvolution2dDescriptor::m_PadBottom, TransposeConvolution2dDescriptor::m_PadLeft, TransposeConvolution2dDescriptor::m_PadRight, TransposeConvolution2dDescriptor::m_PadTop, LayerWithParameters< TransposeConvolution2dDescriptor >::m_Param, TransposeConvolution2dDescriptor::m_StrideX, TransposeConvolution2dDescriptor::m_StrideY, and armnn::NHWC.

Referenced by TransposeConvolution2dInferOutputShapeTest(), and TransposeConvolution2dLayer::ValidateTensorShapesFromInputs().

59 {
60  BOOST_ASSERT(inputShapes.size() == 2);
61  const TensorShape& inputShape = inputShapes[0];
62  const TensorShape& kernelShape = inputShapes[1];
63 
64  BOOST_ASSERT_MSG(inputShape.GetNumDimensions() == 4, "Transpose convolutions will always have 4D input");
65 
66  DataLayoutIndexed dataLayoutIndex(m_Param.m_DataLayout);
67 
68  const unsigned int batches = inputShape[0];
69 
70  const unsigned int wInput = inputShape[dataLayoutIndex.GetWidthIndex()];
71  const unsigned int hInput = inputShape[dataLayoutIndex.GetHeightIndex()];
72 
73  const unsigned int wKernel = kernelShape[dataLayoutIndex.GetWidthIndex()];
74  const unsigned int hKernel = kernelShape[dataLayoutIndex.GetHeightIndex()];
75 
76  unsigned int wPadding = m_Param.m_PadLeft + m_Param.m_PadRight;
77  unsigned int hPadding = m_Param.m_PadTop + m_Param.m_PadBottom;
78 
79  unsigned int wOutput = (wInput - 1) * m_Param.m_StrideX + wKernel - wPadding;
80  unsigned int hOutput = (hInput - 1) * m_Param.m_StrideY + hKernel - hPadding;
81 
82  unsigned int kernelElements = kernelShape[0] * kernelShape[dataLayoutIndex.GetChannelsIndex()];
83  unsigned int inputElements = batches * inputShape[dataLayoutIndex.GetChannelsIndex()];
84 
85  BOOST_ASSERT_MSG(inputElements != 0, "Invalid number of input elements");
86  BOOST_ASSERT_MSG(kernelElements % inputElements == 0, "Invalid number of elements");
87 
88  unsigned int channels = kernelElements / inputElements;
89 
91  TensorShape( { batches, hOutput, wOutput, channels } ) :
92  TensorShape( { batches, channels, hOutput, wOutput });
93 
94  return std::vector<TensorShape>({ tensorShape });
95 }
uint32_t m_PadBottom
Padding bottom value in the height 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_StrideY
Stride value when proceeding through input for the height dimension.
TransposeConvolution2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
uint32_t m_PadRight
Padding right value in the width dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

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

Implements Layer.

Definition at line 97 of file TransposeConvolution2dLayer.cpp.

References CHECK_LOCATION, InputSlot::GetConnection(), Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), TransposeConvolution2dLayer::InferOutputShapes(), TransposeConvolution2dLayer::m_Weight, and Layer::VerifyLayerConnections().

98 {
100 
101  BOOST_ASSERT_MSG(m_Weight != nullptr, "TransposeConvolution2dLayer: Weight data cannot be null.");
102 
103  auto inferredShapes = InferOutputShapes({
105  m_Weight->GetTensorInfo().GetShape() });
106 
107  BOOST_ASSERT(inferredShapes.size() == 1);
108 
109  ConditionalThrowIfNotEqual<LayerValidationException>(
110  "TransposeConvolution2dLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
112  inferredShapes[0]);
113 }
virtual const TensorInfo & GetTensorInfo() const =0
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:337
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Definition: Layer.hpp:312
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.

Member Data Documentation

◆ m_Bias

◆ m_Weight


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