ArmNN
 21.02
ComparisonEndToEndTestImpl.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "CommonTestUtils.hpp"
8 
9 #include <ResolveType.hpp>
10 
11 #include <armnn/INetwork.hpp>
12 
14 
15 #include <boost/test/unit_test.hpp>
16 
17 #include <vector>
18 
19 namespace
20 {
21 
22 template<armnn::DataType ArmnnTypeInput>
23 INetworkPtr CreateComparisonNetwork(const std::vector<TensorShape>& inputShapes,
24  const TensorShape& outputShape,
25  ComparisonOperation operation,
26  const float qScale = 1.0f,
27  const int32_t qOffset = 0)
28 {
29  using namespace armnn;
30 
32 
33  ComparisonDescriptor descriptor(operation);
34  IConnectableLayer* comparisonLayer = net->AddComparisonLayer(descriptor, "comparison");
35 
36  for (unsigned int i = 0; i < inputShapes.size(); ++i)
37  {
38  TensorInfo inputTensorInfo(inputShapes[i], ArmnnTypeInput, qScale, qOffset);
39  IConnectableLayer* input = net->AddInputLayer(armnn::numeric_cast<LayerBindingId>(i));
40  Connect(input, comparisonLayer, inputTensorInfo, 0, i);
41  }
42 
43  TensorInfo outputTensorInfo(outputShape, DataType::Boolean, qScale, qOffset);
44  IConnectableLayer* output = net->AddOutputLayer(0, "output");
45  Connect(comparisonLayer, output, outputTensorInfo, 0, 0);
46 
47  return net;
48 }
49 
50 template<armnn::DataType ArmnnInType,
51  typename TInput = armnn::ResolveType<ArmnnInType>>
52 void ComparisonSimpleEndToEnd(const std::vector<BackendId>& backends,
53  ComparisonOperation operation,
54  const std::vector<uint8_t> expectedOutput)
55 {
56  using namespace armnn;
57 
58  const std::vector<TensorShape> inputShapes{{ 2, 2, 2, 2 }, { 2, 2, 2, 2 }};
59  const TensorShape& outputShape = { 2, 2, 2, 2 };
60 
61  // Builds up the structure of the network
62  INetworkPtr net = CreateComparisonNetwork<ArmnnInType>(inputShapes, outputShape, operation);
63 
64  BOOST_TEST_CHECKPOINT("create a network");
65 
66  const std::vector<TInput> input0({ 1, 1, 1, 1, 5, 5, 5, 5,
67  3, 3, 3, 3, 4, 4, 4, 4 });
68 
69  const std::vector<TInput> input1({ 1, 1, 1, 1, 3, 3, 3, 3,
70  5, 5, 5, 5, 4, 4, 4, 4 });
71 
72  std::map<int, std::vector<TInput>> inputTensorData = {{ 0, input0 }, { 1, input1 }};
73  std::map<int, std::vector<uint8_t>> expectedOutputData = {{ 0, expectedOutput }};
74 
75  EndToEndLayerTestImpl<ArmnnInType, DataType::Boolean>(move(net), inputTensorData, expectedOutputData, backends);
76 }
77 
78 template<armnn::DataType ArmnnInType,
79  typename TInput = armnn::ResolveType<ArmnnInType>>
80 void ComparisonBroadcastEndToEnd(const std::vector<BackendId>& backends,
81  ComparisonOperation operation,
82  const std::vector<uint8_t> expectedOutput)
83 {
84  using namespace armnn;
85 
86  const std::vector<TensorShape> inputShapes{{ 1, 2, 2, 3 }, { 1, 1, 1, 3 }};
87  const TensorShape& outputShape = { 1, 2, 2, 3 };
88 
89  // Builds up the structure of the network
90  INetworkPtr net = CreateComparisonNetwork<ArmnnInType>(inputShapes, outputShape, operation);
91 
92  BOOST_TEST_CHECKPOINT("create a network");
93 
94  const std::vector<TInput> input0({ 1, 2, 3, 1, 0, 6,
95  7, 8, 9, 10, 11, 12 });
96 
97  const std::vector<TInput> input1({ 1, 1, 3 });
98 
99  std::map<int, std::vector<TInput>> inputTensorData = {{ 0, input0 }, { 1, input1 }};
100  std::map<int, std::vector<uint8_t>> expectedOutputData = {{ 0, expectedOutput }};
101 
102  EndToEndLayerTestImpl<ArmnnInType, DataType::Boolean>(move(net), inputTensorData, expectedOutputData, backends);
103 }
104 
105 } // anonymous namespace
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
A ComparisonDescriptor for the ComparisonLayer.
Definition: Descriptors.hpp:78
typename ResolveTypeImpl< DT >::Type ResolveType
Definition: ResolveType.hpp:73
Copyright (c) 2021 ARM Limited and Contributors.
ComparisonOperation
Definition: Types.hpp:78
DataType
Definition: Types.hpp:32
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
Definition: TestUtils.cpp:12
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:173
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:510