29 BOOST_ASSERT_MSG(
m_Weight !=
nullptr,
"TransposeConvolution2dLayer: Weights data should not be null.");
36 BOOST_ASSERT_MSG(
m_Bias !=
nullptr,
"TransposeConvolution2dLayer: Bias data should not be null.");
45 auto layer = CloneBase<TransposeConvolution2dLayer>(graph,
m_Param,
GetName());
47 layer->
m_Weight =
m_Weight ? std::make_unique<ScopedCpuTensorHandle>(*m_Weight) :
nullptr;
49 if (layer->m_Param.m_BiasEnabled)
51 layer->m_Bias =
m_Bias ? std::make_unique<ScopedCpuTensorHandle>(*m_Bias) :
nullptr;
54 return std::move(layer);
58 const std::vector<TensorShape>& inputShapes)
const 60 BOOST_ASSERT(inputShapes.size() == 2);
64 BOOST_ASSERT_MSG(inputShape.GetNumDimensions() == 4,
"Transpose convolutions will always have 4D input");
68 const unsigned int batches = inputShape[0];
70 const unsigned int wInput = inputShape[dataLayoutIndex.GetWidthIndex()];
71 const unsigned int hInput = inputShape[dataLayoutIndex.GetHeightIndex()];
73 const unsigned int wKernel = kernelShape[dataLayoutIndex.GetWidthIndex()];
74 const unsigned int hKernel = kernelShape[dataLayoutIndex.GetHeightIndex()];
79 unsigned int wOutput = (wInput - 1) *
m_Param.
m_StrideX + wKernel - wPadding;
80 unsigned int hOutput = (hInput - 1) *
m_Param.
m_StrideY + hKernel - hPadding;
82 unsigned int kernelElements = kernelShape[0] * kernelShape[dataLayoutIndex.GetChannelsIndex()];
83 unsigned int inputElements = batches * inputShape[dataLayoutIndex.GetChannelsIndex()];
85 BOOST_ASSERT_MSG(inputElements != 0,
"Invalid number of input elements");
86 BOOST_ASSERT_MSG(kernelElements % inputElements == 0,
"Invalid number of elements");
88 unsigned int channels = kernelElements / inputElements;
91 TensorShape( { batches, hOutput, wOutput, channels } ) :
92 TensorShape( { batches, channels, hOutput, wOutput });
94 return std::vector<TensorShape>({ tensorShape });
101 BOOST_ASSERT_MSG(
m_Weight !=
nullptr,
"TransposeConvolution2dLayer: Weight data cannot be null.");
105 m_Weight->GetTensorInfo().GetShape() });
107 BOOST_ASSERT(inferredShapes.size() == 1);
109 ConditionalThrowIfNotEqual<LayerValidationException>(
110 "TransposeConvolution2dLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
This layer represents a 2D transpose convolution operation.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
const char * GetName() const override
void ValidateTensorShapesFromInputs() override
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
virtual const TensorInfo & GetTensorInfo() const =0
uint32_t m_PadTop
Padding top value in the height dimension.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
ConstantTensors GetConstantTensorsByRef() override
const TransposeConvolution2dDescriptor & GetParameters() const
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
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.).
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
uint32_t m_PadRight
Padding right value in the width dimension.
TransposeConvolution2dLayer(const TransposeConvolution2dDescriptor ¶m, const char *name)
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.
const ConstCpuTensorHandle * m_Bias
void Accept(ILayerVisitor &visitor) const override
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
TransposeConvolution2dLayer * Clone(Graph &graph) const override
const ConstCpuTensorHandle * m_Weight
bool m_BiasEnabled
Enable/disable bias.
virtual std::unique_ptr< IWorkload > CreateTransposeConvolution2d(const TransposeConvolution2dQueueDescriptor &descriptor, const WorkloadInfo &info) const
const TensorShape & GetShape() const
const TensorInfo & GetTensorInfo() const override
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
const InputSlot & GetInputSlot(unsigned int index) const override
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store weight values.