ArmNN
 24.02
DetectionPostProcessLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include "LayerCloneBase.hpp"
9 
10 #include <armnn/TypesUtils.hpp>
14 
15 namespace armnn
16 {
17 
20 {
21 }
22 
23 std::unique_ptr<IWorkload> DetectionPostProcessLayer::CreateWorkload(const armnn::IWorkloadFactory& factory) const
24 {
26  descriptor.m_Anchors = m_Anchors.get();
27  SetAdditionalInfo(descriptor);
28 
29  return factory.CreateWorkload(LayerType::DetectionPostProcess, descriptor, PrepInfoAndDesc(descriptor));
30 }
31 
33 {
34  auto layer = CloneBase<DetectionPostProcessLayer>(graph, m_Param, GetName());
35  layer->m_Anchors = m_Anchors ? m_Anchors : nullptr;
36  return std::move(layer);
37 }
38 
40 {
42 
43  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
44 
46 
47  // on this level constant data should not be released.
48  ARMNN_ASSERT_MSG(m_Anchors != nullptr, "DetectionPostProcessLayer: Anchors data should not be null.");
49 
50  ARMNN_ASSERT_MSG(GetNumOutputSlots() == 4, "DetectionPostProcessLayer: The layer should return 4 outputs.");
51 
52  std::vector<TensorShape> inferredShapes = InferOutputShapes(
55 
56  ARMNN_ASSERT(inferredShapes.size() == 4);
57  ARMNN_ASSERT(inferredShapes[0].GetDimensionality() == Dimensionality::Specified);
58  ARMNN_ASSERT(inferredShapes[1].GetDimensionality() == Dimensionality::Specified);
59  ARMNN_ASSERT(inferredShapes[2].GetDimensionality() == Dimensionality::Specified);
60  ARMNN_ASSERT(inferredShapes[3].GetDimensionality() == Dimensionality::Specified);
61 
62  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DetectionPostProcessLayer");
63 
65  inferredShapes[1],
67  "DetectionPostProcessLayer", 1);
68 
70  inferredShapes[2],
72  "DetectionPostProcessLayer", 2);
73 
75  inferredShapes[3],
77  "DetectionPostProcessLayer", 3);
78 }
79 
80 std::vector<TensorShape> DetectionPostProcessLayer::InferOutputShapes(const std::vector<TensorShape>&) const
81 {
82  unsigned int detectedBoxes = m_Param.m_MaxDetections * m_Param.m_MaxClassesPerDetection;
83 
84  std::vector<TensorShape> results;
85  results.push_back({ 1, detectedBoxes, 4 });
86  results.push_back({ 1, detectedBoxes });
87  results.push_back({ 1, detectedBoxes });
88  results.push_back({ 1 });
89  return results;
90 }
91 
93 {
94  // For API stability DO NOT ALTER order and add new members to the end of vector
95  return { m_Anchors };
96 }
97 
99 {
100  ManagedConstTensorHandle managedAnchors(m_Anchors);
101  std::vector<armnn::ConstTensor> constTensors { {managedAnchors.GetTensorInfo(), managedAnchors.Map()} };
102  strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
103 }
104 
105 } // namespace armnn
armnn::DetectionPostProcessLayer::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the DetectionPostProcess type.
Definition: DetectionPostProcessLayer.cpp:23
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::DetectionPostProcessLayer::InferOutputShapes
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
The model does not specify the output shapes.
Definition: DetectionPostProcessLayer.cpp:80
DetectionPostProcessLayer.hpp
armnn::OutputSlot::GetTensorInfo
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:92
WorkloadData.hpp
armnn::DetectionPostProcessDescriptor::m_MaxDetections
uint32_t m_MaxDetections
Maximum numbers of detections.
Definition: Descriptors.hpp:745
TypesUtils.hpp
armnn::DetectionPostProcessLayer::GetConstantTensorsByRef
ImmutableConstantTensors GetConstantTensorsByRef() const override
Retrieve the handles to the constant values stored by the layer.
Definition: DetectionPostProcessLayer.cpp:92
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::Layer::ValidateAndCopyShape
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:435
armnn::Layer::GetOutputSlot
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:339
armnn::IStrategy
Definition: IStrategy.hpp:16
ARMNN_ASSERT_MSG
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
armnn::ManagedConstTensorHandle
Definition: TensorHandle.hpp:187
armnn::DetectionPostProcessDescriptor::m_MaxClassesPerDetection
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
Definition: Descriptors.hpp:747
armnn::DetectionPostProcessQueueDescriptor::m_Anchors
const ConstTensorHandle * m_Anchors
Definition: WorkloadData.hpp:246
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
armnn::LayerWithParameters< DetectionPostProcessDescriptor >::GetParameters
const DetectionPostProcessDescriptor & GetParameters() const override
Definition: LayerWithParameters.hpp:19
WorkloadFactory.hpp
armnn::LayerWithParameters
Definition: LayerWithParameters.hpp:14
armnn::Layer::GetName
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:332
armnn::IConnectableLayer::ImmutableConstantTensors
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
Definition: INetwork.hpp:141
armnn::InputSlot::GetTensorInfo
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition: Layer.cpp:592
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::LayerWithParameters< DetectionPostProcessDescriptor >::m_Param
DetectionPostProcessDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
Definition: LayerWithParameters.hpp:52
armnn::LayerWithParameters< DetectionPostProcessDescriptor >::PrepInfoAndDesc
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
Definition: LayerWithParameters.hpp:44
armnn::IWorkloadFactory
Definition: WorkloadFactory.hpp:22
armnn::DetectionPostProcessQueueDescriptor
Definition: WorkloadData.hpp:239
armnn::Layer::GetNumOutputSlots
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition: Layer.hpp:335
armnn::Layer::VerifyShapeInferenceType
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:504
armnn::GetTensorInfo
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Definition: RefWorkloadUtils.hpp:33
armnn::ManagedConstTensorHandle::Map
const void * Map(bool blocking=true)
RAII Managed resource Unmaps MemoryArea once out of scope.
Definition: TensorHandle.hpp:196
armnn::Layer::SetAdditionalInfo
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:287
armnn::DetectionPostProcess
void DetectionPostProcess(const TensorInfo &boxEncodingsInfo, const TensorInfo &scoresInfo, const TensorInfo &anchorsInfo, const TensorInfo &detectionBoxesInfo, const TensorInfo &detectionClassesInfo, const TensorInfo &detectionScoresInfo, const TensorInfo &numDetectionsInfo, const DetectionPostProcessDescriptor &desc, Decoder< float > &boxEncodings, Decoder< float > &scores, Decoder< float > &anchors, float *detectionBoxes, float *detectionClasses, float *detectionScores, float *numDetections)
Definition: DetectionPostProcess.cpp:141
armnn::LayerType::DetectionPostProcess
@ DetectionPostProcess
armnn::DetectionPostProcessLayer::ValidateTensorShapesFromInputs
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of DetectionPostProcessLayer.
Definition: DetectionPostProcessLayer.cpp:39
armnn::DetectionPostProcessLayer::m_Anchors
std::shared_ptr< ConstTensorHandle > m_Anchors
A unique pointer to store Anchor values.
Definition: DetectionPostProcessLayer.hpp:20
armnn::DetectionPostProcessLayer::ExecuteStrategy
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Definition: DetectionPostProcessLayer.cpp:98
armnn::Dimensionality::Specified
@ Specified
TensorHandle.hpp
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
armnn::DetectionPostProcessLayer::Clone
DetectionPostProcessLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: DetectionPostProcessLayer.cpp:32
armnn::DetectionPostProcessLayer::DetectionPostProcessLayer
DetectionPostProcessLayer(const DetectionPostProcessDescriptor &param, const char *name)
Constructor to create a DetectionPostProcessLayer.
Definition: DetectionPostProcessLayer.cpp:18
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::DetectionPostProcessLayer
This layer represents a detection postprocess operator.
Definition: DetectionPostProcessLayer.hpp:16
armnn::Layer::VerifyLayerConnections
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:391
armnn::DetectionPostProcessDescriptor
Definition: Descriptors.hpp:713
armnn::Layer::m_ShapeInferenceMethod
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:441
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:491
armnn::Graph
Definition: Graph.hpp:30
armnn::IWorkloadFactory::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const =0
Backends should implement their own CreateWorkload function with a switch statement.
armnn::IStrategy::ExecuteStrategy
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
LayerCloneBase.hpp
armnn::ManagedConstTensorHandle::GetTensorInfo
const TensorInfo & GetTensorInfo() const
Definition: TensorHandle.hpp:239