blob: 48db83d7af5010e51abf15f5ee6dc792ade1232a [file] [log] [blame]
Derek Lamberti6a5e5e82019-12-05 14:41:20 +00001//
Teresa Charlin588cbdf2022-01-19 15:55:37 +00002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Derek Lamberti6a5e5e82019-12-05 14:41:20 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "NeonDetectionPostProcessWorkload.hpp"
7
8#include "NeonWorkloadUtils.hpp"
9
10#include <aclCommon/ArmComputeTensorHandle.hpp>
11#include <aclCommon/ArmComputeTensorUtils.hpp>
Jan Eilersbb446e52020-04-02 13:56:54 +010012#include <armnn/utility/PolymorphicDowncast.hpp>
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000013
14namespace armnn
15{
16
Keith Davis2d0679f2021-08-05 11:35:00 +010017arm_compute::DetectionPostProcessLayerInfo MakeInfo(const DetectionPostProcessDescriptor& descriptor)
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000018{
Keith Davis2d0679f2021-08-05 11:35:00 +010019 return arm_compute::DetectionPostProcessLayerInfo(descriptor.m_MaxDetections,
20 descriptor.m_MaxClassesPerDetection,
21 descriptor.m_NmsScoreThreshold,
22 descriptor.m_NmsIouThreshold,
23 descriptor.m_NumClasses,
24 { descriptor.m_ScaleX,
25 descriptor.m_ScaleY,
26 descriptor.m_ScaleW,
27 descriptor.m_ScaleH },
28 descriptor.m_UseRegularNms,
29 descriptor.m_DetectionsPerClass);
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000030}
31
32arm_compute::Status NeonDetectionPostProcessValidate(const TensorInfo& boxEncodings,
33 const TensorInfo& scores,
34 const TensorInfo& anchors,
35 const TensorInfo& detectionBoxes,
36 const TensorInfo& detectionClasses,
37 const TensorInfo& detectionScores,
38 const TensorInfo& numDetections,
Keith Davis2d0679f2021-08-05 11:35:00 +010039 const DetectionPostProcessDescriptor &descriptor)
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000040{
Keith Davis2d0679f2021-08-05 11:35:00 +010041 arm_compute::DetectionPostProcessLayerInfo info = MakeInfo(descriptor);
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000042
43 const arm_compute::TensorInfo aclBoxEncodings =
44 armcomputetensorutils::BuildArmComputeTensorInfo(boxEncodings);
45
46 const arm_compute::TensorInfo aclScores =
47 armcomputetensorutils::BuildArmComputeTensorInfo(scores);
48
49 const arm_compute::TensorInfo aclAnchors =
50 armcomputetensorutils::BuildArmComputeTensorInfo(anchors);
51
52 arm_compute::TensorInfo aclDetectionBoxes =
53 armcomputetensorutils::BuildArmComputeTensorInfo(detectionBoxes);
54
55 arm_compute::TensorInfo aclDetectionClasses =
56 armcomputetensorutils::BuildArmComputeTensorInfo(detectionClasses);
57
58 arm_compute::TensorInfo aclDetectionScores =
59 armcomputetensorutils::BuildArmComputeTensorInfo(detectionScores);
60
61 arm_compute::TensorInfo aclNumDetections =
62 armcomputetensorutils::BuildArmComputeTensorInfo(numDetections);
63
James Conroy99bf80d2020-02-20 11:14:49 +000064 return arm_compute::NEDetectionPostProcessLayer::validate(
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000065 &aclBoxEncodings,
66 &aclScores,
67 &aclAnchors,
68 &aclDetectionBoxes,
69 &aclDetectionClasses,
70 &aclDetectionScores,
71 &aclNumDetections,
72 info);
73}
74
75NeonDetectionPostProcessWorkload::NeonDetectionPostProcessWorkload(
76 const DetectionPostProcessQueueDescriptor& descriptor,
77 const WorkloadInfo& info)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000078 : NeonBaseWorkload<DetectionPostProcessQueueDescriptor>(descriptor, info)
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000079{
Keith Davis2d0679f2021-08-05 11:35:00 +010080 // Report Profiling Details
81 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonDetectionPostProcessWorkload_Construct",
82 descriptor.m_Parameters,
83 info,
84 this->GetGuid());
85
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000086 m_Anchors = std::make_unique<arm_compute::Tensor>();
87 BuildArmComputeTensor(*m_Anchors, descriptor.m_Anchors->GetTensorInfo());
88
89 arm_compute::DetectionPostProcessLayerInfo di = MakeInfo(m_Data.m_Parameters);
90
91 auto AclTensorRef = [](ITensorHandle* tensor) -> arm_compute::ITensor&
92 {
Jan Eilersbb446e52020-04-02 13:56:54 +010093 return PolymorphicDowncast<IAclTensorHandle*>(tensor)->GetTensor();
Derek Lamberti6a5e5e82019-12-05 14:41:20 +000094 };
95
96 arm_compute::ITensor& boxEncodings = AclTensorRef(m_Data.m_Inputs[0]);
97 arm_compute::ITensor& scores = AclTensorRef(m_Data.m_Inputs[1]);
98
99 arm_compute::ITensor& detectionBoxes = AclTensorRef(m_Data.m_Outputs[0]);
100 arm_compute::ITensor& detectionClasses = AclTensorRef(m_Data.m_Outputs[1]);
101 arm_compute::ITensor& detectionScores = AclTensorRef(m_Data.m_Outputs[2]);
102 arm_compute::ITensor& numDetections = AclTensorRef(m_Data.m_Outputs[3]);
103
104 m_Func.configure(&boxEncodings, &scores, m_Anchors.get(),
105 &detectionBoxes, &detectionClasses, &detectionScores, &numDetections,
106 di);
107
108 InitializeArmComputeTensorData(*m_Anchors, m_Data.m_Anchors);
109}
110
111void NeonDetectionPostProcessWorkload::Execute() const
112{
Keith Davis2d0679f2021-08-05 11:35:00 +0100113 ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonDetectionPostProcessWorkload_Execute", this->GetGuid());
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000114 m_Func.run();
115}
116
117} // namespace armnn