32 const std::vector<TensorShape>& inputShapes =
39 unsigned int filterWidth = filterShape[dataLayoutIndex.
GetWidthIndex()];
40 unsigned int filterHeight = filterShape[dataLayoutIndex.
GetHeightIndex()];
41 unsigned int outChannels = filterShape[0];
43 fn(
"OutputChannels",std::to_string(outChannels));
44 fn(
"FilterWidth",std::to_string(filterWidth));
45 fn(
"FilterHeight",std::to_string(filterHeight));
52 BOOST_ASSERT_MSG(
m_Weight !=
nullptr,
"Convolution2dLayer: Weights data should not be null.");
60 BOOST_ASSERT_MSG(
m_Bias !=
nullptr,
"Convolution2dLayer: Bias data should not be null.");
68 auto layer = CloneBase<Convolution2dLayer>(graph,
m_Param,
GetName());
70 layer->
m_Weight =
m_Weight ? std::make_unique<ScopedCpuTensorHandle>(*m_Weight) :
nullptr;
72 if (layer->m_Param.m_BiasEnabled)
74 layer->m_Bias =
m_Bias ? std::make_unique<ScopedCpuTensorHandle>(*m_Bias) :
nullptr;
77 return std::move(layer);
82 BOOST_ASSERT(inputShapes.size() == 2);
87 BOOST_ASSERT_MSG(inputShape.GetNumDimensions() == 4,
"Convolutions will always have 4D input.");
91 unsigned int inWidth = inputShape[dataLayoutIndex.GetWidthIndex()];
92 unsigned int inHeight = inputShape[dataLayoutIndex.GetHeightIndex()];
93 unsigned int inBatchSize = inputShape[0];
95 unsigned int filterWidth = filterShape[dataLayoutIndex.GetWidthIndex()];
96 unsigned int dilatedFilterWidth = filterWidth + (
m_Param.
m_DilationX - 1) * (filterWidth - 1);
100 unsigned int filterHeight = filterShape[dataLayoutIndex.GetHeightIndex()];
101 unsigned int dilatedFilterHeight = filterHeight + (
m_Param.
m_DilationY - 1) * (filterHeight - 1);
105 unsigned int outChannels = filterShape[0];
106 unsigned int outBatchSize = inBatchSize;
109 TensorShape( { outBatchSize, outHeight, outWidth, outChannels } ) :
110 TensorShape( { outBatchSize, outChannels, outHeight, outWidth });
112 return std::vector<TensorShape>({ tensorShape });
120 BOOST_ASSERT_MSG(
m_Weight !=
nullptr,
"Convolution2dLayer: Weights data should not be null.");
124 m_Weight->GetTensorInfo().GetShape() });
126 BOOST_ASSERT(inferredShapes.size() == 1);
128 ConditionalThrowIfNotEqual<LayerValidationException>(
129 "Convolution2dLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
ConstantTensors GetConstantTensorsByRef() override
void Accept(ILayerVisitor &visitor) const override
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
const char * GetName() const override
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
std::unique_ptr< ScopedCpuTensorHandle > m_Bias
A unique pointer to store Bias values.
uint32_t m_PadRight
Padding right value in the width dimension.
virtual void VisitConvolution2dLayer(const IConnectableLayer *layer, const Convolution2dDescriptor &convolution2dDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)=0
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
virtual const TensorInfo & GetTensorInfo() const =0
unsigned int GetHeightIndex() const
This layer represents a convolution 2d operation.
std::unique_ptr< ScopedCpuTensorHandle > m_Weight
A unique pointer to store Weight values.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
void ValidateTensorShapesFromInputs() override
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
const ConstCpuTensorHandle * m_Weight
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
uint32_t m_PadTop
Padding top value in the height dimension.
unsigned int GetWidthIndex() const
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 Convolution2dDescriptor & GetParameters() const
Convolution2dDescriptor 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.
const ConstCpuTensorHandle * m_Bias
bool m_BiasEnabled
Enable/disable bias.
Convolution2dLayer * Clone(Graph &graph) const override
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
Convolution2dLayer(const Convolution2dDescriptor ¶m, const char *name)
virtual std::unique_ptr< IWorkload > CreateConvolution2d(const Convolution2dQueueDescriptor &descriptor, const WorkloadInfo &info) const
uint32_t m_DilationY
Dilation along y axis.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
A Convolution2dDescriptor for the Convolution2dLayer.
uint32_t m_DilationX
Dilation along x axis.
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