ArmNN
 25.11
Loading...
Searching...
No Matches
DetectionPostProcessLayer Class Reference

This layer represents a detection postprocess operator. More...

#include <DetectionPostProcessLayer.hpp>

Inheritance diagram for DetectionPostProcessLayer:
[legend]
Collaboration diagram for DetectionPostProcessLayer:
[legend]

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the DetectionPostProcess type.
DetectionPostProcessLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer.
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of DetectionPostProcessLayer.
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 The model does not specify the output shapes.
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
Public Member Functions inherited from LayerWithParameters< DetectionPostProcessDescriptor >
const DetectionPostProcessDescriptorGetParameters () const override
 If the layer has a descriptor return it.
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
const std::string & GetNameStr () const
const OutputHandlerGetOutputHandler (unsigned int i=0) const
OutputHandlerGetOutputHandler (unsigned int i=0)
ShapeInferenceMethod GetShapeInferenceMethod () const
bool GetAllowExpandedDims () const
const std::vector< InputSlot > & GetInputSlots () const
const std::vector< OutputSlot > & GetOutputSlots () const
std::vector< InputSlot >::iterator BeginInputSlots ()
std::vector< InputSlot >::iterator EndInputSlots ()
std::vector< OutputSlot >::iterator BeginOutputSlots ()
std::vector< OutputSlot >::iterator EndOutputSlots ()
bool IsOutputUnconnected ()
void ResetPriority () const
LayerPriority GetPriority () const
LayerType GetType () const override
 Returns the armnn::LayerType of this layer.
DataType GetDataType () const
const BackendIdGetBackendId () const
void SetBackendId (const BackendId &id) override
 Set the backend of the IConnectableLayer.
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 Infer the shape of the output(s) based on the provided input shape(s)
virtual void ReleaseConstantData ()
template<typename Op>
void OperateOnConstantTensors (Op op)
const char * GetName () const override
 Returns the name of the layer.
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots.
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots.
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index.
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index.
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index.
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index.
void SetGuid (LayerGuid guid)
LayerGuid GetGuid () const final
 Returns the unique id of the layer.
void AddRelatedLayerName (const std::string layerName)
const std::list< std::string > & GetRelatedLayerNames ()
virtual void Reparent (Graph &dest, std::list< Layer * >::const_iterator iterator)=0
void BackendSelectionHint (Optional< BackendId > backend) final
 Provide a hint for the optimizer as to which backend to prefer for this layer.
Optional< BackendIdGetBackendHint () const
void SetShapeInferenceMethod (ShapeInferenceMethod shapeInferenceMethod)
void SetAllowExpandedDims (bool allowExpandedDims)
template<typename T>
std::shared_ptr< T > GetAdditionalInformation () const
void SetAdditionalInfoForObject (const AdditionalInfoObjectPtr &additionalInfo)

Public Attributes

std::shared_ptr< ConstTensorHandlem_Anchors
 A unique pointer to store Anchor values.

Protected Member Functions

 DetectionPostProcessLayer (const DetectionPostProcessDescriptor &param, const char *name)
 Constructor to create a DetectionPostProcessLayer.
 ~DetectionPostProcessLayer ()=default
 Default destructor.
ImmutableConstantTensors GetConstantTensorsByRef () const override
 Retrieve the handles to the constant values stored by the layer.
Protected Member Functions inherited from LayerWithParameters< DetectionPostProcessDescriptor >
 LayerWithParameters (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const DetectionPostProcessDescriptor &param, const char *name)
 ~LayerWithParameters ()=default
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors () const
Protected Member Functions inherited from Layer
virtual ~Layer ()=default
template<typename QueueDescriptor>
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
template<typename QueueDescriptor>
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
void ValidateAndCopyShape (const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
void VerifyShapeInferenceType (const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
template<typename QueueDescriptor>
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
template<typename LayerType, typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
virtual ConstantTensors GetConstantTensorsByRef () override final
void SetAdditionalInfo (QueueDescriptor &descriptor) const
Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle.

Additional Inherited Members

Public Types inherited from LayerWithParameters< DetectionPostProcessDescriptor >
using DescriptorType
Public Types inherited from IConnectableLayer
using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>
using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>
Protected Attributes inherited from LayerWithParameters< DetectionPostProcessDescriptor >
DetectionPostProcessDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.).
Protected Attributes inherited from Layer
AdditionalInfoObjectPtr m_AdditionalInfoObject
std::vector< OutputHandlerm_OutputHandlers
ShapeInferenceMethod m_ShapeInferenceMethod

Detailed Description

This layer represents a detection postprocess operator.

Definition at line 16 of file DetectionPostProcessLayer.hpp.

Constructor & Destructor Documentation

◆ DetectionPostProcessLayer()

DetectionPostProcessLayer ( const DetectionPostProcessDescriptor & param,
const char * name )
protected

Constructor to create a DetectionPostProcessLayer.

Parameters
[in]paramDetectionPostProcessDescriptor to configure the detection postprocess.
[in]nameOptional name for the layer.

Definition at line 18 of file DetectionPostProcessLayer.cpp.

19 : LayerWithParameters(2, 4, LayerType::DetectionPostProcess, param, name)
20{
21}

References armnn::DetectionPostProcess(), and LayerWithParameters< DetectionPostProcessDescriptor >::LayerWithParameters().

Referenced by Clone().

◆ ~DetectionPostProcessLayer()

~DetectionPostProcessLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Clone()

DetectionPostProcessLayer * Clone ( Graph & graph) const
overridevirtual

Creates a dynamically-allocated copy of this layer.

Parameters
[in]graphThe graph into which this layer is being cloned.

Implements Layer.

Definition at line 32 of file DetectionPostProcessLayer.cpp.

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}

References Layer::CloneBase(), DetectionPostProcessLayer(), Layer::GetName(), m_Anchors, and LayerWithParameters< DetectionPostProcessDescriptor >::m_Param.

◆ CreateWorkload()

std::unique_ptr< IWorkload > CreateWorkload ( const IWorkloadFactory & factory) const
overridevirtual

Makes a workload for the DetectionPostProcess type.

Parameters
[in]graphThe graph where this layer can be found.
[in]factoryThe workload factory which will create the workload.
Returns
A pointer to the created workload, or nullptr if not created.

Implements Layer.

Definition at line 23 of file DetectionPostProcessLayer.cpp.

24{
25 DetectionPostProcessQueueDescriptor descriptor;
26 descriptor.m_Anchors = m_Anchors.get();
27 SetAdditionalInfo(descriptor);
28
29 return factory.CreateWorkload(LayerType::DetectionPostProcess, descriptor, PrepInfoAndDesc(descriptor));
30}

References IWorkloadFactory::CreateWorkload(), armnn::DetectionPostProcess, m_Anchors, DetectionPostProcessQueueDescriptor::m_Anchors, LayerWithParameters< DetectionPostProcessDescriptor >::PrepInfoAndDesc(), and Layer::SetAdditionalInfo().

◆ ExecuteStrategy()

void ExecuteStrategy ( IStrategy & strategy) const
overridevirtual

Apply a visitor to this layer.

Implements IConnectableLayer.

Definition at line 112 of file DetectionPostProcessLayer.cpp.

113{
114 ManagedConstTensorHandle managedAnchors(m_Anchors);
115 std::vector<armnn::ConstTensor> constTensors { {managedAnchors.GetTensorInfo(), managedAnchors.Map()} };
116 strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
117}

References IStrategy::ExecuteStrategy(), Layer::GetName(), LayerWithParameters< DetectionPostProcessDescriptor >::GetParameters(), ManagedConstTensorHandle::GetTensorInfo(), m_Anchors, and ManagedConstTensorHandle::Map().

◆ GetConstantTensorsByRef()

Layer::ImmutableConstantTensors GetConstantTensorsByRef ( ) const
overrideprotectedvirtual

Retrieve the handles to the constant values stored by the layer.

Returns
A vector of the constant tensors stored by this layer.

Reimplemented from Layer.

Definition at line 106 of file DetectionPostProcessLayer.cpp.

107{
108 // For API stability DO NOT ALTER order and add new members to the end of vector
109 return { m_Anchors };
110}

References m_Anchors.

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > & inputShapes) const
overridevirtual

The model does not specify the output shapes.

The output shapes are calculated from the max_detection and max_classes_per_detection parameters in the DetectionPostProcessDescriptor.

Parameters
[in]inputShapesThe input shapes layer has. These are ignored for DetectionPostProcessLayer.
Returns
A vector to the inferred output shape.

Implements IConnectableLayer.

Definition at line 94 of file DetectionPostProcessLayer.cpp.

95{
96 unsigned int detectedBoxes = m_Param.m_MaxDetections * m_Param.m_MaxClassesPerDetection;
97
98 std::vector<TensorShape> results;
99 results.push_back({ 1, detectedBoxes, 4 });
100 results.push_back({ 1, detectedBoxes });
101 results.push_back({ 1, detectedBoxes });
102 results.push_back({ 1 });
103 return results;
104}

References LayerWithParameters< DetectionPostProcessDescriptor >::m_Param.

Referenced by ValidateTensorShapesFromInputs().

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of DetectionPostProcessLayer.

Parameters
[in]shapeInferenceMethodIndicates if output shape shall be overwritten or just validated.

Implements Layer.

Definition at line 39 of file DetectionPostProcessLayer.cpp.

40{
41 VerifyLayerConnections(2, CHECK_LOCATION());
42
43 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
44
45 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
46
47 // on this level constant data should not be released.
48 if (!m_Anchors)
49 {
50 throw armnn::LayerValidationException("DetectionPostProcessLayer: Anchors data should not be null.");
51 }
52
53 if (GetNumOutputSlots() != 4)
54 {
55 throw armnn::LayerValidationException("DetectionPostProcessLayer: The layer should return 4 outputs.");
56 }
57
58 std::vector<TensorShape> inferredShapes = InferOutputShapes(
59 { GetInputSlot(0).GetTensorInfo().GetShape(),
60 GetInputSlot(1).GetTensorInfo().GetShape() });
61
62 if (inferredShapes.size() != 4)
63 {
64 throw armnn::LayerValidationException("inferredShapes has "
65 + std::to_string(inferredShapes.size()) +
66 " element(s) - should only have 4.");
67 }
68
69 if (std::any_of(inferredShapes.begin(), inferredShapes.end(), [] (auto&& inferredShape) {
70 return inferredShape.GetDimensionality() != Dimensionality::Specified;
71 }))
72 {
73 throw armnn::Exception("One of inferredShapes' dimensionalities is not specified.");
74 }
75
76 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "DetectionPostProcessLayer");
77
78 ValidateAndCopyShape(GetOutputSlot(1).GetTensorInfo().GetShape(),
79 inferredShapes[1],
80 m_ShapeInferenceMethod,
81 "DetectionPostProcessLayer", 1);
82
83 ValidateAndCopyShape(GetOutputSlot(2).GetTensorInfo().GetShape(),
84 inferredShapes[2],
85 m_ShapeInferenceMethod,
86 "DetectionPostProcessLayer", 2);
87
88 ValidateAndCopyShape(GetOutputSlot(3).GetTensorInfo().GetShape(),
89 inferredShapes[3],
90 m_ShapeInferenceMethod,
91 "DetectionPostProcessLayer", 3);
92}
#define CHECK_LOCATION()
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)

References CHECK_LOCATION, Layer::GetInputSlot(), Layer::GetNumOutputSlots(), Layer::GetOutputSlot(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), armnnUtils::GetTensorInfo(), InferOutputShapes(), m_Anchors, Layer::m_ShapeInferenceMethod, Layer::ValidateAndCopyShape(), Layer::VerifyLayerConnections(), and Layer::VerifyShapeInferenceType().

Member Data Documentation

◆ m_Anchors

std::shared_ptr<ConstTensorHandle> m_Anchors

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