Compute Library
 21.02
NEDetectionPostProcessLayer Class Reference

NE Function to generate the detection output based on center size encoded boxes, class prediction and anchors by doing non maximum suppression. More...

#include <NEDetectionPostProcessLayer.h>

Collaboration diagram for NEDetectionPostProcessLayer:
[legend]

Public Member Functions

 NEDetectionPostProcessLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 NEDetectionPostProcessLayer (const NEDetectionPostProcessLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEDetectionPostProcessLayeroperator= (const NEDetectionPostProcessLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ~NEDetectionPostProcessLayer ()=default
 Default destructor. More...
 
void configure (const ITensor *input_box_encoding, const ITensor *input_score, const ITensor *input_anchors, ITensor *output_boxes, ITensor *output_classes, ITensor *output_scores, ITensor *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
 Configure the detection output layer NE function. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input_box_encoding, const ITensorInfo *input_class_score, const ITensorInfo *input_anchors, ITensorInfo *output_boxes, ITensorInfo *output_classes, ITensorInfo *output_scores, ITensorInfo *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
 Static function to check if given info will lead to a valid configuration of NEDetectionPostProcessLayer. More...
 

Detailed Description

NE Function to generate the detection output based on center size encoded boxes, class prediction and anchors by doing non maximum suppression.

Note
Intended for use with MultiBox detection method.

Definition at line 47 of file NEDetectionPostProcessLayer.h.

Constructor & Destructor Documentation

◆ NEDetectionPostProcessLayer() [1/2]

NEDetectionPostProcessLayer ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Constructor.

Definition at line 36 of file NEDetectionPostProcessLayer.cpp.

37  : _memory_group(std::move(memory_manager)), _dequantize(), _detection_post_process(), _decoded_scores(), _run_dequantize(false)
38 {
39 }

◆ NEDetectionPostProcessLayer() [2/2]

Prevent instances of this class from being copied (As this class contains pointers)

◆ ~NEDetectionPostProcessLayer()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input_box_encoding,
const ITensor input_score,
const ITensor input_anchors,
ITensor output_boxes,
ITensor output_classes,
ITensor output_scores,
ITensor num_detection,
DetectionPostProcessLayerInfo  info = DetectionPostProcessLayerInfo() 
)

Configure the detection output layer NE function.

Parameters
[in]input_box_encodingThe bounding box input tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F32.
[in]input_scoreThe class prediction input tensor. Data types supported: same as input_box_encoding.
[in]input_anchorsThe anchors input tensor. Data types supported: same as input_box_encoding.
[out]output_boxesThe boxes output tensor. Data types supported: F32.
[out]output_classesThe classes output tensor. Data types supported: Same as output_boxes.
[out]output_scoresThe scores output tensor. Data types supported: Same as output_boxes.
[out]num_detectionThe number of output detection. Data types supported: Same as output_boxes.
[in]info(Optional) DetectionPostProcessLayerInfo information.
Note
Output contains all the detections. Of those, only the ones selected by the valid region are valid.

Definition at line 41 of file NEDetectionPostProcessLayer.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, NEDequantizationLayer::configure(), CPPDetectionPostProcessLayer::configure(), ITensorInfo::data_type(), DetectionPostProcessLayerInfo::detection_per_class(), ITensor::info(), arm_compute::test::validation::info, DetectionPostProcessLayerInfo::iou_threshold(), arm_compute::is_data_type_quantized(), MemoryGroup::manage(), DetectionPostProcessLayerInfo::max_classes_per_detection(), DetectionPostProcessLayerInfo::max_detections(), DetectionPostProcessLayerInfo::nms_score_threshold(), DetectionPostProcessLayerInfo::num_classes(), DetectionPostProcessLayerInfo::scale_value_h(), DetectionPostProcessLayerInfo::scale_value_w(), DetectionPostProcessLayerInfo::scale_value_x(), DetectionPostProcessLayerInfo::scale_value_y(), DetectionPostProcessLayerInfo::use_regular_nms(), and NEDetectionPostProcessLayer::validate().

43 {
44  ARM_COMPUTE_ERROR_ON_NULLPTR(input_box_encoding, input_scores, input_anchors, output_boxes, output_classes, output_scores);
45  ARM_COMPUTE_ERROR_THROW_ON(NEDetectionPostProcessLayer::validate(input_box_encoding->info(), input_scores->info(), input_anchors->info(), output_boxes->info(), output_classes->info(),
46  output_scores->info(),
47  num_detection->info(), info));
48 
49  const ITensor *input_scores_to_use = input_scores;
50  DetectionPostProcessLayerInfo info_to_use = info;
51  _run_dequantize = is_data_type_quantized(input_box_encoding->info()->data_type());
52 
53  if(_run_dequantize)
54  {
55  _memory_group.manage(&_decoded_scores);
56 
57  _dequantize.configure(input_scores, &_decoded_scores);
58 
59  input_scores_to_use = &_decoded_scores;
60 
61  // Create a new info struct to avoid dequantizing in the CPP layer
62  std::array<float, 4> scales_values{ info.scale_value_y(), info.scale_value_x(), info.scale_value_h(), info.scale_value_w() };
63  DetectionPostProcessLayerInfo info_quantized(info.max_detections(), info.max_classes_per_detection(), info.nms_score_threshold(), info.iou_threshold(), info.num_classes(),
64  scales_values, info.use_regular_nms(), info.detection_per_class(), false);
65  info_to_use = info_quantized;
66  }
67 
68  _detection_post_process.configure(input_box_encoding, input_scores_to_use, input_anchors, output_boxes, output_classes, output_scores, num_detection, info_to_use);
69  _decoded_scores.allocator()->allocate();
70 }
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1168
void configure(const ITensor *input, ITensor *output)
Configure the kernel.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void configure(const ITensor *input_box_encoding, const ITensor *input_score, const ITensor *input_anchors, ITensor *output_boxes, ITensor *output_classes, ITensor *output_scores, ITensor *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
Configure the detection output layer CPP function.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
static Status validate(const ITensorInfo *input_box_encoding, const ITensorInfo *input_class_score, const ITensorInfo *input_anchors, ITensorInfo *output_boxes, ITensorInfo *output_classes, ITensorInfo *output_scores, ITensorInfo *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
Static function to check if given info will lead to a valid configuration of NEDetectionPostProcessLa...

◆ operator=()

Prevent instances of this class from being copied (As this class contains pointers)

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For Neon kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 86 of file NEDetectionPostProcessLayer.cpp.

References INESimpleFunctionNoBorder::run(), and CPPDetectionPostProcessLayer::run().

87 {
88  MemoryGroupResourceScope scope_mg(_memory_group);
89 
90  // Decode scores if necessary
91  if(_run_dequantize)
92  {
93  _dequantize.run();
94  }
95  _detection_post_process.run();
96 }
void run() override final
Run the kernels contained in the function.
void run() override
Run the kernels contained in the function.

◆ validate()

Status validate ( const ITensorInfo input_box_encoding,
const ITensorInfo input_class_score,
const ITensorInfo input_anchors,
ITensorInfo output_boxes,
ITensorInfo output_classes,
ITensorInfo output_scores,
ITensorInfo num_detection,
DetectionPostProcessLayerInfo  info = DetectionPostProcessLayerInfo() 
)
static

Static function to check if given info will lead to a valid configuration of NEDetectionPostProcessLayer.

Parameters
[in]input_box_encodingThe bounding box input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F32.
[in]input_class_scoreThe class prediction input tensor info. Data types supported: same as input_box_encoding.
[in]input_anchorsThe anchors input tensor info. Data types supported: same as input_box_encoding.
[in]output_boxesThe output tensor info. Data types supported: F32.
[in]output_classesThe output tensor info. Data types supported: Same as output_boxes.
[in]output_scoresThe output tensor info. Data types supported: Same as output_boxes.
[in]num_detectionThe number of output detection tensor info. Data types supported: Same as output_boxes.
[in]info(Optional) DetectionPostProcessLayerInfo information.
Returns
a status

Definition at line 72 of file NEDetectionPostProcessLayer.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), ITensorInfo::data_type(), arm_compute::F32, arm_compute::is_data_type_quantized(), NEDequantizationLayer::validate(), and CPPDetectionPostProcessLayer::validate().

Referenced by NEDetectionPostProcessLayer::configure(), and arm_compute::test::validation::DATA_TEST_CASE().

74 {
75  bool run_dequantize = is_data_type_quantized(input_box_encoding->data_type());
76  if(run_dequantize)
77  {
78  TensorInfo decoded_classes_info = input_scores->clone()->set_is_resizable(true).set_data_type(DataType::F32);
79  ARM_COMPUTE_RETURN_ON_ERROR(NEDequantizationLayer::validate(input_scores, &decoded_classes_info));
80  }
81  ARM_COMPUTE_RETURN_ON_ERROR(CPPDetectionPostProcessLayer::validate(input_box_encoding, input_scores, input_anchors, output_boxes, output_classes, output_scores, num_detection, info));
82 
83  return Status{};
84 }
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1168
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
static Status validate(const ITensorInfo *input_box_encoding, const ITensorInfo *input_class_score, const ITensorInfo *input_anchors, ITensorInfo *output_boxes, ITensorInfo *output_classes, ITensorInfo *output_scores, ITensorInfo *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
Static function to check if given info will lead to a valid configuration of CPPDetectionPostProcessL...
1 channel, 1 F32 per channel
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NEDequantizationLayer.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

The documentation for this class was generated from the following files: