ArmNN
 21.05
DetectionPostProcess.cpp File Reference
#include "../TfLiteParser.hpp"
#include "ParserFlatbuffersFixture.hpp"
#include "ParserPrototxtFixture.hpp"
#include "ParserHelper.hpp"
#include "test/GraphUtils.hpp"
#include <armnn/utility/PolymorphicDowncast.hpp>
#include <QuantizeHelper.hpp>
#include <boost/test/unit_test.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(), armnn::GetGraphForTesting(), 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  armnn::Graph& graph = GetGraphForTesting(optimized.get());
245 
246  // Check the number of layers in the graph
247  BOOST_TEST((graph.GetNumInputs() == 2));
248  BOOST_TEST((graph.GetNumOutputs() == 4));
249  BOOST_TEST((graph.GetNumLayers() == 7));
250 
251  // Input layers
252  armnn::Layer* boxEncodingLayer = GetFirstLayerWithName(graph, "box_encodings");
253  BOOST_TEST((boxEncodingLayer->GetType() == armnn::LayerType::Input));
254  BOOST_TEST(CheckNumberOfInputSlot(boxEncodingLayer, 0));
255  BOOST_TEST(CheckNumberOfOutputSlot(boxEncodingLayer, 1));
256 
257  armnn::Layer* scoresLayer = GetFirstLayerWithName(graph, "scores");
258  BOOST_TEST((scoresLayer->GetType() == armnn::LayerType::Input));
259  BOOST_TEST(CheckNumberOfInputSlot(scoresLayer, 0));
260  BOOST_TEST(CheckNumberOfOutputSlot(scoresLayer, 1));
261 
262  // DetectionPostProcess layer
263  armnn::Layer* detectionPostProcessLayer = GetFirstLayerWithName(graph, "DetectionPostProcess:0:0");
264  BOOST_TEST((detectionPostProcessLayer->GetType() == armnn::LayerType::DetectionPostProcess));
265  BOOST_TEST(CheckNumberOfInputSlot(detectionPostProcessLayer, 2));
266  BOOST_TEST(CheckNumberOfOutputSlot(detectionPostProcessLayer, 4));
267 
268  // Output layers
269  armnn::Layer* detectionBoxesLayer = GetFirstLayerWithName(graph, "detection_boxes");
270  BOOST_TEST((detectionBoxesLayer->GetType() == armnn::LayerType::Output));
271  BOOST_TEST(CheckNumberOfInputSlot(detectionBoxesLayer, 1));
272  BOOST_TEST(CheckNumberOfOutputSlot(detectionBoxesLayer, 0));
273 
274  armnn::Layer* detectionClassesLayer = GetFirstLayerWithName(graph, "detection_classes");
275  BOOST_TEST((detectionClassesLayer->GetType() == armnn::LayerType::Output));
276  BOOST_TEST(CheckNumberOfInputSlot(detectionClassesLayer, 1));
277  BOOST_TEST(CheckNumberOfOutputSlot(detectionClassesLayer, 0));
278 
279  armnn::Layer* detectionScoresLayer = GetFirstLayerWithName(graph, "detection_scores");
280  BOOST_TEST((detectionScoresLayer->GetType() == armnn::LayerType::Output));
281  BOOST_TEST(CheckNumberOfInputSlot(detectionScoresLayer, 1));
282  BOOST_TEST(CheckNumberOfOutputSlot(detectionScoresLayer, 0));
283 
284  armnn::Layer* numDetectionsLayer = GetFirstLayerWithName(graph, "num_detections");
285  BOOST_TEST((numDetectionsLayer->GetType() == armnn::LayerType::Output));
286  BOOST_TEST(CheckNumberOfInputSlot(numDetectionsLayer, 1));
287  BOOST_TEST(CheckNumberOfOutputSlot(numDetectionsLayer, 0));
288 
289  // Check the connections
290  armnn::TensorInfo boxEncodingTensor(armnn::TensorShape({ 1, 6, 4 }), armnn::DataType::QAsymmU8, 1, 1);
292  0.00999999978f, 0);
293 
294  armnn::TensorInfo detectionBoxesTensor(armnn::TensorShape({ 1, 3, 4 }), armnn::DataType::Float32, 0, 0);
295  armnn::TensorInfo detectionClassesTensor(armnn::TensorShape({ 1, 3 }), armnn::DataType::Float32, 0, 0);
296  armnn::TensorInfo detectionScoresTensor(armnn::TensorShape({ 1, 3 }), armnn::DataType::Float32, 0, 0);
297  armnn::TensorInfo numDetectionsTensor(armnn::TensorShape({ 1} ), armnn::DataType::Float32, 0, 0);
298 
299  BOOST_TEST(IsConnected(boxEncodingLayer, detectionPostProcessLayer, 0, 0, boxEncodingTensor));
300  BOOST_TEST(IsConnected(scoresLayer, detectionPostProcessLayer, 0, 1, scoresTensor));
301  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionBoxesLayer, 0, 0, detectionBoxesTensor));
302  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionClassesLayer, 1, 0, detectionClassesTensor));
303  BOOST_TEST(IsConnected(detectionPostProcessLayer, detectionScoresLayer, 2, 0, detectionScoresTensor));
304  BOOST_TEST(IsConnected(detectionPostProcessLayer, numDetectionsLayer, 3, 0, numDetectionsTensor));
305 }
CPU Execution: Reference C++ kernels.
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:22
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:1568
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
Definition: Layer.hpp:265
bool IsConnected(armnn::Layer *srcLayer, armnn::Layer *destLayer, unsigned int srcSlot, unsigned int destSlot, const armnn::TensorInfo &expectedTensorInfo)
Definition: GraphUtils.cpp:44
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
Definition: TestUtils.cpp:25
bool CheckNumberOfInputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:34
bool CheckNumberOfOutputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:39
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:173