MCPcopy Create free account
hub / github.com/OAID/Tengine / Run

Method Run

executor/operator/common/detection_output.cpp:128–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126 }
127
128 bool Run(Node* node)
129 {
130 const Tensor* loc_tensor = node->GetInputTensor(0);
131 const Tensor* conf_tensor = node->GetInputTensor(1);
132 const Tensor* priorbox_tensor = node->GetInputTensor(2);
133 Tensor* output_tensor = node->GetOutputTensor(0);
134
135 DetectionOutput* detect_op = dynamic_cast<DetectionOutput*>(node->GetOp());
136 DetectionOutputParam* param_ = detect_op->GetParam();
137
138 // location [b,num_prior*4,1,1]
139 float* location = ( float* )get_tensor_mem(loc_tensor);
140 // confidence [b,num_prior*21,1,1]
141 float* confidence = ( float* )get_tensor_mem(conf_tensor);
142 // priorbox [b,2,num_prior*4,1]
143 float* priorbox = ( float* )get_tensor_mem(priorbox_tensor);
144
145 const std::vector<int>& dims = priorbox_tensor->GetShape().GetDim();
146 const int num_priorx4 = dims[2];
147 const int num_prior = num_priorx4 / 4;
148 const int num_classes = param_->num_classes;
149 // const int batch=dims[0];
150
151 // only support for batch=1
152
153 // for(int b=0;b<batch;b++)
154 //{
155 int b = 0;
156 float* loc_ptr = location + b * num_priorx4;
157 float* conf_ptr = confidence + b * num_prior * num_classes;
158 float* prior_ptr = priorbox + b * num_priorx4 * 2;
159
160 std::vector<Box> boxes(num_prior);
161 get_boxes(boxes, num_prior, loc_ptr, prior_ptr);
162
163 std::vector<std::vector<Box>> all_class_bbox_rects;
164 all_class_bbox_rects.resize(num_classes);
165 // start from 1 to ignore background class
166 for(int i = 1; i < num_classes; i++)
167 {
168 std::vector<Box> class_box;
169 for(int j = 0; j < num_prior; j++)
170 {
171 float score = conf_ptr[j * num_classes + i];
172 if(score > param_->confidence_threshold)
173 {
174 boxes[j].score = score;
175 boxes[j].class_idx = i;
176 class_box.push_back(boxes[j]);
177 }
178 }
179 // sort
180 std::sort(class_box.begin(), class_box.end(), [](const Box& a, const Box& b) { return a.score > b.score; });
181
182 // keep nms_top_k
183 if(param_->nms_top_k < ( int )class_box.size())
184 {
185 class_box.resize(param_->nms_top_k);

Callers

nothing calls this directly

Calls 12

get_tensor_memFunction · 0.85
get_boxesFunction · 0.85
set_tensor_memFunction · 0.85
GetOpMethod · 0.80
GetParamMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
SetDimMethod · 0.80
nms_sorted_bboxesFunction · 0.50
GetInputTensorMethod · 0.45
GetOutputTensorMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected