22 {
23
24 Layer& base = connection.GetConnectedOutputSlot()->GetOwningLayer();
26 const TensorInfo& inputInfo = base.GetInputSlot(0).GetTensorInfo();
27 const TensorInfo& intermediateInfo = base.GetOutputSlot(0).GetTensorInfo();
28 if (intermediateInfo.GetNumDimensions() != 4)
29 {
30
31 return;
32 }
33 if (!static_cast<PermuteType&>(base).GetParameters().m_DimMappings.IsEqual(PermutationVector{ 3, 1, 2, 0 }))
34 {
35
36
37 return;
38 }
39
40
41 Layer& child = connection.GetOwningLayer();
43 const TensorInfo& outputInfo = child.GetOutputSlot(0).GetTensorInfo();
44 const BatchToSpaceNdDescriptor& batchToSpaceDesc = static_cast<BatchToSpaceNdLayer&>(child).GetParameters();
46 {
47
48 return;
49 }
50 if (batchToSpaceDesc.m_Crops != std::vector<std::pair<unsigned int, unsigned int>>{ { 0, 0 }, { 0, 0 } })
51 {
52
53 return;
54 }
55 if (batchToSpaceDesc.m_BlockShape.size() != 2 ||
56 batchToSpaceDesc.m_BlockShape[0] != batchToSpaceDesc.m_BlockShape[1])
57 {
58
59 return;
60 }
61 uint32_t blockSize = batchToSpaceDesc.m_BlockShape[0];
62 if (outputInfo.GetShape()[0] != 1 || outputInfo.GetShape()[3] != 1)
63 {
64
65
66 return;
67 }
68
69
70
71
72
73
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
86 const std::string name = std::string("merged-") + base.GetName() + std::string("-with-") + child.GetName();
87
88
90 auto& depthToSpace = *graph.InsertNewLayer<DepthToSpaceLayer>(base.GetInputSlot(0),
91 depthToSpaceDesc,
92 name.c_str());
93
94
95
96
97 child.GetOutputSlot().MoveAllConnections(depthToSpace.GetOutputSlot());
98 }
#define ARMNN_ASSERT(COND)
SpaceToDepthDescriptor DepthToSpaceDescriptor
A DepthToSpaceDescriptor for the DepthToSpaceLayer.