ArmNN  NotReleased
SpaceToDepthLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "SpaceToDepthLayer.hpp"
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/TypesUtils.hpp>
10 
12 
15 
16 #include <numeric>
17 
18 #include <boost/core/ignore_unused.hpp>
19 
20 using namespace armnnUtils;
21 
22 namespace armnn
23 {
24 
26  : LayerWithParameters(1, 1, LayerType::SpaceToDepth, param, name)
27 {}
28 
29 std::unique_ptr<IWorkload> SpaceToDepthLayer::CreateWorkload(const IWorkloadFactory& factory) const
30 {
31  SpaceToDepthQueueDescriptor descriptor;
34 
35  return factory.CreateSpaceToDepth(descriptor, PrepInfoAndDesc(descriptor));
36 }
37 
39 {
40  boost::ignore_unused(graph);
41  return CloneBase<SpaceToDepthLayer>(graph, m_Param, GetName());
42 }
43 
44 std::vector<TensorShape> SpaceToDepthLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
45 {
46  BOOST_ASSERT(inputShapes.size() == 1);
47 
48  TensorShape inputShape = inputShapes[0];
49  TensorShape outputShape(inputShape);
50 
51  DataLayoutIndexed dimensionIndices{m_Param.m_DataLayout};
52  unsigned int hIndex = dimensionIndices.GetHeightIndex();
53  unsigned int wIndex = dimensionIndices.GetWidthIndex();
54  unsigned int cIndex = dimensionIndices.GetChannelsIndex();
55 
56  outputShape[hIndex] = inputShape[hIndex] / m_Param.m_BlockSize;
57  outputShape[wIndex] = inputShape[wIndex] / m_Param.m_BlockSize;
58 
59  outputShape[cIndex] = inputShape[cIndex] * m_Param.m_BlockSize * m_Param.m_BlockSize;
60 
61  return std::vector<TensorShape>({ outputShape });
62 }
63 
65 {
67 
68  std::vector<TensorShape> inferredShapes = InferOutputShapes({
70 
71  BOOST_ASSERT(inferredShapes.size() == 1);
72 
73  ConditionalThrowIfNotEqual<LayerValidationException>(
74  "SpaceToDepthLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
76  inferredShapes[0]);
77 }
78 
80 {
81  visitor.VisitSpaceToDepthLayer(this, GetParameters(), GetName());
82 }
83 
84 } // namespace armnn
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
const char * GetName() const override
Definition: Layer.hpp:305
virtual const TensorInfo & GetTensorInfo() const =0
SpaceToDepthLayer * Clone(Graph &graph) const override
This layer represents a SpaceToDepth operation.
#define CHECK_LOCATION()
Definition: Exceptions.hpp:169
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
const SpaceToDepthDescriptor & GetParameters() const
virtual std::unique_ptr< IWorkload > CreateSpaceToDepth(const SpaceToDepthQueueDescriptor &descriptor, const WorkloadInfo &info) const
SpaceToDepthDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:337
virtual void VisitSpaceToDepthLayer(const IConnectableLayer *layer, const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)=0
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
void SpaceToDepth(const TensorInfo &inputInfo, const TensorInfo &outputInfo, const SpaceToDepthDescriptor &params, Decoder< float > &inputData, Encoder< float > &outputData)
SpaceToDepthLayer(const SpaceToDepthDescriptor param, const char *name)
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
void ValidateTensorShapesFromInputs() override
void Accept(ILayerVisitor &visitor) const override
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
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
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
const InputSlot & GetInputSlot(unsigned int index) const override
Definition: Layer.hpp:310