From 6940dd720ebb6b3d1df8ca203ab696daefe58189 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 20 Mar 2020 12:25:56 +0000 Subject: renamed Documentation folder 20.02 and added .nojekyll file Signed-off-by: Jim Flynn --- ...and_batch_to_space_as_depth_to_space_impl.xhtml | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 20.02/classarmnn_1_1optimizations_1_1_permute_and_batch_to_space_as_depth_to_space_impl.xhtml (limited to '20.02/classarmnn_1_1optimizations_1_1_permute_and_batch_to_space_as_depth_to_space_impl.xhtml') diff --git a/20.02/classarmnn_1_1optimizations_1_1_permute_and_batch_to_space_as_depth_to_space_impl.xhtml b/20.02/classarmnn_1_1optimizations_1_1_permute_and_batch_to_space_as_depth_to_space_impl.xhtml new file mode 100644 index 0000000000..acd4e03f13 --- /dev/null +++ b/20.02/classarmnn_1_1optimizations_1_1_permute_and_batch_to_space_as_depth_to_space_impl.xhtml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + +ArmNN: PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType > Class Template Reference + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  20.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType > Class Template Reference
+
+
+ +

Replaces Permute leading into BatchToSpace with a DepthToSpace in the case where the Permute swaps the batch and channels dimensions such that the replacement is valid. + More...

+ +

#include <PermuteAndBatchToSpaceAsDepthToSpace.hpp>

+ + + + +

+Public Member Functions

void Run (Graph &graph, InputSlot &connection) const
 
+

Detailed Description

+

template<typename PermuteType>
+class armnn::optimizations::PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteType >

+ +

Replaces Permute leading into BatchToSpace with a DepthToSpace in the case where the Permute swaps the batch and channels dimensions such that the replacement is valid.

+ +

Definition at line 18 of file PermuteAndBatchToSpaceAsDepthToSpace.hpp.

+

Member Function Documentation

+ +

◆ Run()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
void Run (Graphgraph,
InputSlotconnection 
) const
+
+inline
+
+ +

Definition at line 21 of file PermuteAndBatchToSpaceAsDepthToSpace.hpp.

+ +

References armnn::BatchToSpaceNd, InputSlot::GetConnectedOutputSlot(), InputSlot::GetConnection(), Layer::GetInputSlot(), Layer::GetName(), TensorInfo::GetNumDimensions(), Layer::GetOutputHandler(), Layer::GetOutputSlot(), InputSlot::GetOwningLayer(), OutputSlot::GetOwningLayer(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), Layer::GetType(), BatchToSpaceNdDescriptor::m_Crops, BatchToSpaceNdDescriptor::m_DataLayout, armnn::NHWC, armnn::Permute, OutputHandler::SetTensorInfo(), and armnn::Transpose.

+
22  {
23  // Validate base layer (the Permute) is compatible
24  Layer& base = connection.GetConnectedOutputSlot()->GetOwningLayer();
25  BOOST_ASSERT(base.GetType() == LayerType::Permute || base.GetType() == LayerType::Transpose);
26  const TensorInfo& inputInfo = base.GetInputSlot(0).GetConnection()->GetTensorInfo();
27  const TensorInfo& intermediateInfo = base.GetOutputSlot(0).GetTensorInfo();
28  if (intermediateInfo.GetNumDimensions() != 4)
29  {
30  // Must be 4D, otherwise the below checks do not make sense
31  return;
32  }
33  if (!static_cast<PermuteType&>(base).GetParameters().m_DimMappings.IsEqual(PermutationVector{ 3, 1, 2, 0 }))
34  {
35  // Must swap batch and channels dimensions, otherwise it is not the (original) channels dimension
36  // that is being decomposed.
37  return;
38  }
39 
40  // Validate child layer (the BatchToSpace) is compatible
41  Layer& child = connection.GetOwningLayer();
42  BOOST_ASSERT(child.GetType() == LayerType::BatchToSpaceNd);
43  const TensorInfo& outputInfo = child.GetOutputSlot(0).GetTensorInfo();
44  const BatchToSpaceNdDescriptor& batchToSpaceDesc = static_cast<BatchToSpaceNdLayer&>(child).GetParameters();
45  if (batchToSpaceDesc.m_DataLayout != DataLayout::NHWC)
46  {
47  // The rest of this function assumes NHWC, although in future this restriction could be lifted.
48  return;
49  }
50  if (batchToSpaceDesc.m_Crops != std::vector<std::pair<unsigned int, unsigned int>>{ { 0, 0 }, { 0, 0 } })
51  {
52  // Cropping is not supported in DepthToSpace
53  return;
54  }
55  if (batchToSpaceDesc.m_BlockShape.size() != 2 ||
56  batchToSpaceDesc.m_BlockShape[0] != batchToSpaceDesc.m_BlockShape[1])
57  {
58  // Asymmetric or non-2D block sizes are not supported by DepthToSpace
59  return;
60  }
61  uint32_t blockSize = batchToSpaceDesc.m_BlockShape[0];
62  if (outputInfo.GetShape()[0] != 1 || outputInfo.GetShape()[3] != 1)
63  {
64  // The final output must have 1 batch and 1 channel because these dimensions will be swapped around
65  // once we make the substitution, and it needs to be equivalent.
66  return;
67  }
68 
69  // Validate the intermediate tensor quantization params.
70  // These must be identical to either the input or output quantization params, otherwise the intermediate tensor
71  // may not have sufficient range/precision to preserve the values.
72  // This would mean that once we perform the substitution this loss of precision will no longer occur,
73  // so we would have changed the meaning of the network.
74  bool isIntermediateQuantParamsSameAsInput =
75  intermediateInfo.GetQuantizationScale() == inputInfo.GetQuantizationScale() &&
76  intermediateInfo.GetQuantizationOffset() == inputInfo.GetQuantizationOffset();
77  bool isIntermediateQuantParamsSameAsOutput =
78  intermediateInfo.GetQuantizationScale() == outputInfo.GetQuantizationScale() &&
79  intermediateInfo.GetQuantizationOffset() == outputInfo.GetQuantizationOffset();
80  if (!isIntermediateQuantParamsSameAsInput && !isIntermediateQuantParamsSameAsOutput)
81  {
82  return;
83  }
84 
85  // Insert equivalent DepthToSpace layer
86  const std::string name = std::string("merged-") + base.GetName() + std::string("-with-") + child.GetName();
87 
88  // Inserts equivalent reshape before base layer.
89  const DepthToSpaceDescriptor depthToSpaceDesc(blockSize, DataLayout::NHWC);
90  auto& depthToSpace = *graph.InsertNewLayer<DepthToSpaceLayer>(base.GetInputSlot(0),
91  depthToSpaceDesc,
92  name.c_str());
93  depthToSpace.GetOutputHandler().SetTensorInfo(outputInfo);
94 
95  // Moves connections from child output to new layer.
96  // Child layer will be removed as it's left unconnected.
97  // Base layer will be removed if left unconnected.
98  child.GetOutputSlot().MoveAllConnections(depthToSpace.GetOutputSlot());
99  }
+ + + +
SpaceToDepthDescriptor DepthToSpaceDescriptor
A DepthToSpaceDescriptor for the DepthToSpaceLayer.
+
+
+
+
The documentation for this class was generated from the following file: +
+
+ + + + -- cgit v1.2.1