ArmNN
 20.02
DetectionPostProcess.cpp File Reference
#include "../TfLiteParser.hpp"
#include <boost/test/unit_test.hpp>
#include "test/GraphUtils.hpp"
#include "ParserFlatbuffersFixture.hpp"
#include "ParserPrototxtFixture.hpp"
#include "ParserHelper.hpp"
#include <QuantizeHelper.hpp>

Go to the source code of this file.

Functions

 BOOST_FIXTURE_TEST_CASE (ParseDetectionPostProcess, ParseDetectionPostProcessCustomOptions)
 
 BOOST_FIXTURE_TEST_CASE (DetectionPostProcessGraphStructureTest, ParseDetectionPostProcessCustomOptions)
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/2]

BOOST_FIXTURE_TEST_CASE ( ParseDetectionPostProcess  ,
ParseDetectionPostProcessCustomOptions   
)

Definition at line 164 of file DetectionPostProcess.cpp.

References boxEncodings(), and scores().

165 {
166  Setup();
167 
168  // Inputs
169  using UnquantizedContainer = std::vector<float>;
170  UnquantizedContainer boxEncodings =
171  {
172  0.0f, 0.0f, 0.0f, 0.0f,
173  0.0f, 1.0f, 0.0f, 0.0f,
174  0.0f, -1.0f, 0.0f, 0.0f,
175  0.0f, 0.0f, 0.0f, 0.0f,
176  0.0f, 1.0f, 0.0f, 0.0f,
177  0.0f, 0.0f, 0.0f, 0.0f
178  };
179 
180  UnquantizedContainer scores =
181  {
182  0.0f, 0.9f, 0.8f,
183  0.0f, 0.75f, 0.72f,
184  0.0f, 0.6f, 0.5f,
185  0.0f, 0.93f, 0.95f,
186  0.0f, 0.5f, 0.4f,
187  0.0f, 0.3f, 0.2f
188  };
189 
190  // Outputs
191  UnquantizedContainer detectionBoxes =
192  {
193  0.0f, 10.0f, 1.0f, 11.0f,
194  0.0f, 10.0f, 1.0f, 11.0f,
195  0.0f, 0.0f, 0.0f, 0.0f
196  };
197 
198  UnquantizedContainer detectionClasses = { 1.0f, 0.0f, 0.0f };
199  UnquantizedContainer detectionScores = { 0.95f, 0.93f, 0.0f };
200 
201  UnquantizedContainer numDetections = { 2.0f };
202 
203  // Quantize inputs and outputs
204  using QuantizedContainer = std::vector<uint8_t>;
205 
206  QuantizedContainer quantBoxEncodings = armnnUtils::QuantizedVector<uint8_t>(boxEncodings, 1.00f, 1);
207  QuantizedContainer quantScores = armnnUtils::QuantizedVector<uint8_t>(scores, 0.01f, 0);
208 
209  std::map<std::string, QuantizedContainer> input =
210  {
211  { "box_encodings", quantBoxEncodings },
212  { "scores", quantScores }
213  };
214 
215  std::map<std::string, UnquantizedContainer> output =
216  {
217  { "detection_boxes", detectionBoxes},
218  { "detection_classes", detectionClasses},
219  { "detection_scores", detectionScores},
220  { "num_detections", numDetections}
221  };
222 
223  RunTest<armnn::DataType::QAsymmU8, armnn::DataType::Float32>(0, input, output);
224 }
std::vector< float > boxEncodings({ 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f })
std::vector< float > scores({ 0.0f, 0.9f, 0.8f, 0.0f, 0.75f, 0.72f, 0.0f, 0.6f, 0.5f, 0.0f, 0.93f, 0.95f, 0.0f, 0.5f, 0.4f, 0.0f, 0.3f, 0.2f })

◆ BOOST_FIXTURE_TEST_CASE() [2/2]

BOOST_FIXTURE_TEST_CASE ( DetectionPostProcessGraphStructureTest  ,
ParseDetectionPostProcessCustomOptions   
)

Definition at line 226 of file DetectionPostProcess.cpp.

References BOOST_AUTO_TEST_SUITE_END(), CheckNumberOfInputSlot(), CheckNumberOfOutputSlot(), armnn::CpuRef, armnn::DetectionPostProcess, armnn::Float32, GetFirstLayerWithName(), Layer::GetType(), armnn::Input, IsConnected(), armnn::Optimize(), armnn::Output, and armnn::QAsymmU8.

227 {
228  /*
229  Inputs: box_encodings scores
230  \ /
231  DetectionPostProcess
232  / / \ \
233  / / \ \
234  Outputs: detection detection detection num_detections
235  boxes classes scores
236  */
237 
238  ReadStringToBinary();
239 
240  armnn::INetworkPtr network = m_Parser->CreateNetworkFromBinary(m_GraphBinary);
241 
242  auto optimized = Optimize(*network, { armnn::Compute::CpuRef }, m_Runtime->GetDeviceSpec());
243 
244  auto optimizedNetwork = boost::polymorphic_downcast<armnn::OptimizedNetwork*>(optimized.get());
245  auto graph = optimizedNetwork->GetGraph();
246 
247  // Check the number of layers in the graph
248  BOOST_TEST((graph.GetNumInputs() == 2));
249  BOOST_TEST((graph.GetNumOutputs() == 4));
250  BOOST_TEST((graph.GetNumLayers() == 7));
251 
252  // Input layers
253  armnn::Layer* boxEncodingLayer = GetFirstLayerWithName(graph, "box_encodings");
254  BOOST_TEST((boxEncodingLayer->GetType() == armnn::LayerType::Input));
255  BOOST_TEST(CheckNumberOfInputSlot(boxEncodingLayer, 0));
256  BOOST_TEST(CheckNumberOfOutputSlot(boxEncodingLayer, 1));
257 
258  armnn::Layer* scoresLayer = GetFirstLayerWithName(graph, "scores");
259  BOOST_TEST((scoresLayer->GetType() == armnn::LayerType::Input));
260  BOOST_TEST(CheckNumberOfInputSlot(scoresLayer, 0));
261  BOOST_TEST(CheckNumberOfOutputSlot(scoresLayer, 1));
262 
263  // DetectionPostProcess layer
264  armnn::Layer* detectionPostProcessLayer = GetFirstLayerWithName(graph, "DetectionPostProcess:0:0");
265  BOOST_TEST((detectionPostProcessLayer->GetType() == armnn::LayerType::DetectionPostProcess));
266  BOOST_TEST(CheckNumberOfInputSlot(detectionPostProcessLayer, 2));
267  BOOST_TEST(CheckNumberOfOutputSlot(detectionPostProcessLayer, 4));
268 
269  // Output layers
270  armnn::Layer* detectionBoxesLayer = GetFirstLayerWithName(graph, "detection_boxes");
271  BOOST_TEST((detectionBoxesLayer->GetType() == armnn::LayerType::Output));
272  BOOST_TEST(CheckNumberOfInputSlot(detectionBoxesLayer, 1));
273  BOOST_TEST(CheckNumberOfOutputSlot(detectionBoxesLayer, 0));
274 
275  armnn::Layer* detectionClassesLayer = GetFirstLayerWithName(graph, "detection_classes");
276  BOOST_TEST((detectionClassesLayer->GetType() == armnn::LayerType::Output));
277  BOOST_TEST(CheckNumberOfInputSlot(detectionClassesLayer, 1));
278  BOOST_TEST(CheckNumberOfOutputSlot(detectionClassesLayer, 0));
279 
280  armnn::Layer* detectionScoresLayer = GetFirstLayerWithName(graph, "detection_scores");
281  BOOST_TEST((detectionScoresLayer->GetType() == armnn::LayerType::Output));
282  BOOST_TEST(CheckNumberOfInputSlot(detectionScoresLayer, 1));
283  BOOST_TEST(CheckNumberOfOutputSlot(detectionScoresLayer, 0));
284 
285  armnn::Layer* numDetectionsLayer = GetFirstLayerWithName(graph, "num_detections");
286  BOOST_TEST((numDetectionsLayer->GetType() == armnn::LayerType::Output));
287  BOOST_TEST(CheckNumberOfInputSlot(numDetectionsLayer, 1));
288  BOOST_TEST(CheckNumberOfOutputSlot(numDetectionsLayer, 0));
289 
290  // Check the connections
291  armnn::TensorInfo boxEncodingTensor(armnn::TensorShape({ 1, 6, 4 }), armnn::DataType::QAsymmU8, 1, 1);
293  0.00999999978f, 0);
294 
295  armnn::TensorInfo detectionBoxesTensor(armnn::TensorShape({ 1, 3, 4 }), armnn::DataType::Float32, 0, 0);
296  armnn::TensorInfo detectionClassesTensor(armnn::TensorShape({ 1, 3 }), armnn::DataType::Float32, 0, 0);
297  armnn::TensorInfo detectionScoresTensor(armnn::TensorShape({ 1, 3 }), armnn::DataType::Float32, 0, 0);
298  armnn::TensorInfo numDetectionsTensor(armnn::TensorShape({ 1} ), armnn::DataType::Float32, 0, 0);
299 
300  BOOST_TEST(IsConnected(boxEncodingLayer, detectionPostProcessLayer, 0, 0, boxEncodingTensor));
301  BOOST_TEST(IsConnected(scoresLayer, detectionPostProcessLayer, 0, 1, scoresTensor));
302  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionBoxesLayer, 0, 0, detectionBoxesTensor));
303  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionClassesLayer, 1, 0, detectionClassesTensor));
304  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionScoresLayer, 2, 0, detectionScoresTensor));
305  BOOST_TEST(IsConnected(detectionPostProcessLayer, numDetectionsLayer, 3, 0, numDetectionsTensor));
306 }
CPU Execution: Reference C++ kernels.
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:20
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:890
bool IsConnected(armnn::Layer *srcLayer, armnn::Layer *destLayer, unsigned int srcSlot, unsigned int destSlot, const armnn::TensorInfo &expectedTensorInfo)
Definition: GraphUtils.cpp:42
LayerType GetType() const
Definition: Layer.hpp:259
bool CheckNumberOfInputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:32
bool CheckNumberOfOutputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:37
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101