ArmNN
 22.05.01
DetectionPostProcessTestImpl.hpp File Reference

Go to the source code of this file.

Functions

template<typename FactoryType , armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
void DetectionPostProcessImpl (const armnn::TensorInfo &boxEncodingsInfo, const armnn::TensorInfo &scoresInfo, const armnn::TensorInfo &anchorsInfo, const std::vector< T > &boxEncodingsData, const std::vector< T > &scoresData, const std::vector< T > &anchorsData, const std::vector< float > &expectedDetectionBoxes, const std::vector< float > &expectedDetectionClasses, const std::vector< float > &expectedDetectionScores, const std::vector< float > &expectedNumDetections, bool useRegularNms)
 
template<armnn::DataType QuantizedType, typename RawType = armnn::ResolveType<QuantizedType>>
void QuantizeData (RawType *quant, const float *dequant, const armnn::TensorInfo &info)
 
template<typename FactoryType >
void DetectionPostProcessRegularNmsFloatTest ()
 
template<typename FactoryType , armnn::DataType QuantizedType, typename RawType = armnn::ResolveType<QuantizedType>>
void DetectionPostProcessRegularNmsQuantizedTest ()
 
template<typename FactoryType >
void DetectionPostProcessFastNmsFloatTest ()
 
template<typename FactoryType , armnn::DataType QuantizedType, typename RawType = armnn::ResolveType<QuantizedType>>
void DetectionPostProcessFastNmsQuantizedTest ()
 

Function Documentation

◆ DetectionPostProcessFastNmsFloatTest()

void DetectionPostProcessFastNmsFloatTest ( )

Definition at line 324 of file DetectionPostProcessTestImpl.hpp.

References armnn::Float32.

325 {
326  return DetectionPostProcessImpl<FactoryType, armnn::DataType::Float32>(
327  armnn::TensorInfo(TestData::s_BoxEncodingsShape, armnn::DataType::Float32),
328  armnn::TensorInfo(TestData::s_ScoresShape, armnn::DataType::Float32),
329  armnn::TensorInfo(TestData::s_AnchorsShape, armnn::DataType::Float32),
330  TestData::s_BoxEncodings,
331  TestData::s_Scores,
332  TestData::s_Anchors,
333  FastNmsExpectedResults::s_DetectionBoxes,
334  FastNmsExpectedResults::s_DetectionClasses,
335  FastNmsExpectedResults::s_DetectionScores,
336  FastNmsExpectedResults::s_NumDetections,
337  false);
338 }

◆ DetectionPostProcessFastNmsQuantizedTest()

void DetectionPostProcessFastNmsQuantizedTest ( )

Definition at line 343 of file DetectionPostProcessTestImpl.hpp.

References TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

344 {
345  armnn::TensorInfo boxEncodingsInfo(TestData::s_BoxEncodingsShape, QuantizedType);
346  armnn::TensorInfo scoresInfo(TestData::s_ScoresShape, QuantizedType);
347  armnn::TensorInfo anchorsInfo(TestData::s_AnchorsShape, QuantizedType);
348 
349  boxEncodingsInfo.SetQuantizationScale(TestData::s_BoxEncodingsQuantData.first);
350  boxEncodingsInfo.SetQuantizationOffset(TestData::s_BoxEncodingsQuantData.second);
351 
352  scoresInfo.SetQuantizationScale(TestData::s_ScoresQuantData.first);
353  scoresInfo.SetQuantizationOffset(TestData::s_ScoresQuantData.second);
354 
355  anchorsInfo.SetQuantizationScale(TestData::s_AnchorsQuantData.first);
356  anchorsInfo.SetQuantizationOffset(TestData::s_BoxEncodingsQuantData.second);
357 
358  std::vector<RawType> boxEncodingsData(TestData::s_BoxEncodingsShape.GetNumElements());
359  QuantizeData<QuantizedType>(boxEncodingsData.data(),
360  TestData::s_BoxEncodings.data(),
361  boxEncodingsInfo);
362 
363  std::vector<RawType> scoresData(TestData::s_ScoresShape.GetNumElements());
364  QuantizeData<QuantizedType>(scoresData.data(),
365  TestData::s_Scores.data(),
366  scoresInfo);
367 
368  std::vector<RawType> anchorsData(TestData::s_AnchorsShape.GetNumElements());
369  QuantizeData<QuantizedType>(anchorsData.data(),
370  TestData::s_Anchors.data(),
371  anchorsInfo);
372 
373  return DetectionPostProcessImpl<FactoryType, QuantizedType>(
374  boxEncodingsInfo,
375  scoresInfo,
376  anchorsInfo,
377  boxEncodingsData,
378  scoresData,
379  anchorsData,
380  FastNmsExpectedResults::s_DetectionBoxes,
381  FastNmsExpectedResults::s_DetectionClasses,
382  FastNmsExpectedResults::s_DetectionScores,
383  FastNmsExpectedResults::s_NumDetections,
384  false);
385 }

◆ DetectionPostProcessImpl()

void DetectionPostProcessImpl ( const armnn::TensorInfo boxEncodingsInfo,
const armnn::TensorInfo scoresInfo,
const armnn::TensorInfo anchorsInfo,
const std::vector< T > &  boxEncodingsData,
const std::vector< T > &  scoresData,
const std::vector< T > &  anchorsData,
const std::vector< float > &  expectedDetectionBoxes,
const std::vector< float > &  expectedDetectionClasses,
const std::vector< float > &  expectedDetectionScores,
const std::vector< float > &  expectedNumDetections,
bool  useRegularNms 
)

Definition at line 141 of file DetectionPostProcessTestImpl.hpp.

References AllocateAndCopyDataToITensorHandle(), CompareTensors(), CopyDataFromITensorHandle(), CopyDataToITensorHandle(), armnn::DetectionPostProcess, armnn::Float32, ProfilerManager::GetInstance(), QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, DetectionPostProcessDescriptor::m_UseRegularNms, and ProfilerManager::RegisterProfiler().

152 {
153  std::unique_ptr<armnn::IProfiler> profiler = std::make_unique<armnn::IProfiler>();
155 
156  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
157  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
158  auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
159 
160  armnn::TensorInfo detectionBoxesInfo({ 1, 3, 4 }, armnn::DataType::Float32);
161  armnn::TensorInfo detectionClassesInfo({ 1, 3 }, armnn::DataType::Float32);
162  armnn::TensorInfo detectionScoresInfo({ 1, 3 }, armnn::DataType::Float32);
163  armnn::TensorInfo numDetectionInfo({ 1 }, armnn::DataType::Float32);
164 
165  std::vector<float> actualDetectionBoxesOutput(detectionBoxesInfo.GetNumElements());
166  std::vector<float> actualDetectionClassesOutput(detectionClassesInfo.GetNumElements());
167  std::vector<float> actualDetectionScoresOutput(detectionScoresInfo.GetNumElements());
168  std::vector<float> actualNumDetectionOutput(numDetectionInfo.GetNumElements());
169 
170  auto boxedHandle = tensorHandleFactory.CreateTensorHandle(boxEncodingsInfo);
171  auto scoreshandle = tensorHandleFactory.CreateTensorHandle(scoresInfo);
172  auto anchorsHandle = tensorHandleFactory.CreateTensorHandle(anchorsInfo);
173  auto outputBoxesHandle = tensorHandleFactory.CreateTensorHandle(detectionBoxesInfo);
174  auto classesHandle = tensorHandleFactory.CreateTensorHandle(detectionClassesInfo);
175  auto outputScoresHandle = tensorHandleFactory.CreateTensorHandle(detectionScoresInfo);
176  auto numDetectionHandle = tensorHandleFactory.CreateTensorHandle(numDetectionInfo);
177 
178  armnn::ScopedTensorHandle anchorsTensor(anchorsInfo);
179  AllocateAndCopyDataToITensorHandle(&anchorsTensor, anchorsData.data());
180 
182  data.m_Parameters.m_UseRegularNms = useRegularNms;
183  data.m_Parameters.m_MaxDetections = 3;
184  data.m_Parameters.m_MaxClassesPerDetection = 1;
185  data.m_Parameters.m_DetectionsPerClass =1;
186  data.m_Parameters.m_NmsScoreThreshold = 0.0;
187  data.m_Parameters.m_NmsIouThreshold = 0.5;
188  data.m_Parameters.m_NumClasses = 2;
189  data.m_Parameters.m_ScaleY = 10.0;
190  data.m_Parameters.m_ScaleX = 10.0;
191  data.m_Parameters.m_ScaleH = 5.0;
192  data.m_Parameters.m_ScaleW = 5.0;
193  data.m_Anchors = &anchorsTensor;
194 
196  AddInputToWorkload(data, info, boxEncodingsInfo, boxedHandle.get());
197  AddInputToWorkload(data, info, scoresInfo, scoreshandle.get());
198  AddOutputToWorkload(data, info, detectionBoxesInfo, outputBoxesHandle.get());
199  AddOutputToWorkload(data, info, detectionClassesInfo, classesHandle.get());
200  AddOutputToWorkload(data, info, detectionScoresInfo, outputScoresHandle.get());
201  AddOutputToWorkload(data, info, numDetectionInfo, numDetectionHandle.get());
202 
203  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateWorkload(armnn::LayerType::DetectionPostProcess,
204  data,
205  info);
206 
207  boxedHandle->Allocate();
208  scoreshandle->Allocate();
209  outputBoxesHandle->Allocate();
210  classesHandle->Allocate();
211  outputScoresHandle->Allocate();
212  numDetectionHandle->Allocate();
213 
214  CopyDataToITensorHandle(boxedHandle.get(), boxEncodingsData.data());
215  CopyDataToITensorHandle(scoreshandle.get(), scoresData.data());
216 
217  workload->Execute();
218 
219  CopyDataFromITensorHandle(actualDetectionBoxesOutput.data(), outputBoxesHandle.get());
220  CopyDataFromITensorHandle(actualDetectionClassesOutput.data(), classesHandle.get());
221  CopyDataFromITensorHandle(actualDetectionScoresOutput.data(), outputScoresHandle.get());
222  CopyDataFromITensorHandle(actualNumDetectionOutput.data(), numDetectionHandle.get());
223 
224  auto result = CompareTensors(actualDetectionBoxesOutput,
225  expectedDetectionBoxes,
226  outputBoxesHandle->GetShape(),
227  detectionBoxesInfo.GetShape());
228  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
229 
230  result = CompareTensors(actualDetectionClassesOutput,
231  expectedDetectionClasses,
232  classesHandle->GetShape(),
233  detectionClassesInfo.GetShape());
234  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
235 
236  result = CompareTensors(actualDetectionScoresOutput,
237  expectedDetectionScores,
238  outputScoresHandle->GetShape(),
239  detectionScoresInfo.GetShape());
240  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
241 
242  result = CompareTensors(actualNumDetectionOutput,
243  expectedNumDetections,
244  numDetectionHandle->GetShape(),
245  numDetectionInfo.GetShape());
246  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
247 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:572
void AllocateAndCopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
void CopyDataFromITensorHandle(void *mem, const armnn::ITensorHandle *tensorHandle)
bool m_UseRegularNms
Use Regular NMS.
armnn::PredicateResult CompareTensors(const std::vector< T > &actualData, const std::vector< T > &expectedData, const armnn::TensorShape &actualShape, const armnn::TensorShape &expectedShape, bool compareBoolean=false, bool isDynamic=false)
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:579
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
Contains information about TensorInfos of a layer.

◆ DetectionPostProcessRegularNmsFloatTest()

void DetectionPostProcessRegularNmsFloatTest ( )

Definition at line 260 of file DetectionPostProcessTestImpl.hpp.

References armnn::Float32.

261 {
262  return DetectionPostProcessImpl<FactoryType, armnn::DataType::Float32>(
263  armnn::TensorInfo(TestData::s_BoxEncodingsShape, armnn::DataType::Float32),
264  armnn::TensorInfo(TestData::s_ScoresShape, armnn::DataType::Float32),
265  armnn::TensorInfo(TestData::s_AnchorsShape, armnn::DataType::Float32),
266  TestData::s_BoxEncodings,
267  TestData::s_Scores,
268  TestData::s_Anchors,
269  RegularNmsExpectedResults::s_DetectionBoxes,
270  RegularNmsExpectedResults::s_DetectionClasses,
271  RegularNmsExpectedResults::s_DetectionScores,
272  RegularNmsExpectedResults::s_NumDetections,
273  true);
274 }

◆ DetectionPostProcessRegularNmsQuantizedTest()

void DetectionPostProcessRegularNmsQuantizedTest ( )

Definition at line 279 of file DetectionPostProcessTestImpl.hpp.

References TensorInfo::SetQuantizationOffset(), and TensorInfo::SetQuantizationScale().

280 {
281  armnn::TensorInfo boxEncodingsInfo(TestData::s_BoxEncodingsShape, QuantizedType);
282  armnn::TensorInfo scoresInfo(TestData::s_ScoresShape, QuantizedType);
283  armnn::TensorInfo anchorsInfo(TestData::s_AnchorsShape, QuantizedType);
284 
285  boxEncodingsInfo.SetQuantizationScale(TestData::s_BoxEncodingsQuantData.first);
286  boxEncodingsInfo.SetQuantizationOffset(TestData::s_BoxEncodingsQuantData.second);
287 
288  scoresInfo.SetQuantizationScale(TestData::s_ScoresQuantData.first);
289  scoresInfo.SetQuantizationOffset(TestData::s_ScoresQuantData.second);
290 
291  anchorsInfo.SetQuantizationScale(TestData::s_AnchorsQuantData.first);
292  anchorsInfo.SetQuantizationOffset(TestData::s_BoxEncodingsQuantData.second);
293 
294  std::vector<RawType> boxEncodingsData(TestData::s_BoxEncodingsShape.GetNumElements());
295  QuantizeData<QuantizedType>(boxEncodingsData.data(),
296  TestData::s_BoxEncodings.data(),
297  boxEncodingsInfo);
298 
299  std::vector<RawType> scoresData(TestData::s_ScoresShape.GetNumElements());
300  QuantizeData<QuantizedType>(scoresData.data(),
301  TestData::s_Scores.data(),
302  scoresInfo);
303 
304  std::vector<RawType> anchorsData(TestData::s_AnchorsShape.GetNumElements());
305  QuantizeData<QuantizedType>(anchorsData.data(),
306  TestData::s_Anchors.data(),
307  anchorsInfo);
308 
309  return DetectionPostProcessImpl<FactoryType, QuantizedType>(
310  boxEncodingsInfo,
311  scoresInfo,
312  anchorsInfo,
313  boxEncodingsData,
314  scoresData,
315  anchorsData,
316  RegularNmsExpectedResults::s_DetectionBoxes,
317  RegularNmsExpectedResults::s_DetectionClasses,
318  RegularNmsExpectedResults::s_DetectionScores,
319  RegularNmsExpectedResults::s_NumDetections,
320  true);
321 }

◆ QuantizeData()

void QuantizeData ( RawType *  quant,
const float *  dequant,
const armnn::TensorInfo info 
)

Definition at line 250 of file DetectionPostProcessTestImpl.hpp.

References TensorInfo::GetNumElements(), TensorInfo::GetQuantizationOffset(), and TensorInfo::GetQuantizationScale().

Referenced by TEST_SUITE().

251 {
252  for (size_t i = 0; i < info.GetNumElements(); i++)
253  {
254  quant[i] = armnn::Quantize<RawType>(
255  dequant[i], info.GetQuantizationScale(), info.GetQuantizationOffset());
256  }
257 }
int32_t GetQuantizationOffset() const
Definition: Tensor.cpp:478
float GetQuantizationScale() const
Definition: Tensor.cpp:461
unsigned int GetNumElements() const
Definition: Tensor.hpp:196