ArmNN
 25.11
Loading...
Searching...
No Matches
DetectionPostProcessLayer.cpp
Go to the documentation of this file.
1//
2// Copyright © 2017-2024 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
15namespace armnn
16{
17
22
23std::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{
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 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(
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
79 inferredShapes[1],
81 "DetectionPostProcessLayer", 1);
82
84 inferredShapes[2],
86 "DetectionPostProcessLayer", 2);
87
89 inferredShapes[3],
91 "DetectionPostProcessLayer", 3);
92}
93
94std::vector<TensorShape> DetectionPostProcessLayer::InferOutputShapes(const std::vector<TensorShape>&) const
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}
105
107{
108 // For API stability DO NOT ALTER order and add new members to the end of vector
109 return { m_Anchors };
110}
111
113{
114 ManagedConstTensorHandle managedAnchors(m_Anchors);
115 std::vector<armnn::ConstTensor> constTensors { {managedAnchors.GetTensorInfo(), managedAnchors.Map()} };
116 strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
117}
118
119} // namespace armnn
#define CHECK_LOCATION()
ImmutableConstantTensors GetConstantTensorsByRef() const override
Retrieve the handles to the constant values stored by the layer.
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
The model does not specify the output shapes.
std::shared_ptr< ConstTensorHandle > m_Anchors
A unique pointer to store Anchor values.
DetectionPostProcessLayer(const DetectionPostProcessDescriptor &param, const char *name)
Constructor to create a DetectionPostProcessLayer.
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of DetectionPostProcessLayer.
DetectionPostProcessLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the DetectionPostProcess type.
Base class for all ArmNN exceptions so that users can filter to just those.
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > > > ImmutableConstantTensors
Definition INetwork.hpp:141
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
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.
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition Layer.cpp:614
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition Layer.cpp:410
unsigned int GetNumOutputSlots() const override
Returns the number of connectable output slots.
Definition Layer.hpp:335
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition Layer.cpp:526
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition Layer.hpp:339
LayerType * CloneBase(Graph &graph, Params &&... params) const
const char * GetName() const override
Returns the name of the layer.
Definition Layer.hpp:332
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition Layer.cpp:457
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition Layer.cpp:303
ShapeInferenceMethod m_ShapeInferenceMethod
Definition Layer.hpp:441
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const DetectionPostProcessDescriptor &param, const char *name)
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
const DetectionPostProcessDescriptor & GetParameters() const override
const void * Map(bool blocking=true)
RAII Managed resource Unmaps MemoryArea once out of scope.
const TensorInfo & GetTensorInfo() const
const TensorInfo & GetTensorInfo() const override
Definition Layer.cpp:100
const TensorShape & GetShape() const
Definition Tensor.hpp:193
Copyright (c) 2021 ARM Limited and Contributors.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
void DetectionPostProcess(const TensorInfo &boxEncodingsInfo, const TensorInfo &scoresInfo, const TensorInfo &, const TensorInfo &detectionBoxesInfo, const TensorInfo &, const TensorInfo &, const TensorInfo &, const DetectionPostProcessDescriptor &desc, Decoder< float > &boxEncodings, Decoder< float > &scores, Decoder< float > &anchors, float *detectionBoxes, float *detectionClasses, float *detectionScores, float *numDetections)
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
const ConstTensorHandle * m_Anchors