File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ rtdetr :
2+ onnx_file : " ../weights/rtdetr/rtdetr_r50vd_6x_coco.onnx"
3+ engine_file : " ../weights/rtdetr/rtdetr_r50vd.trt"
4+ type : " coco80"
5+ mode : " fp32"
6+ batchSize : 1
7+ inputChannel : 3
8+ imageWidth : 640
9+ imageHeight : 640
10+ obj_threshold : 0.25
11+ nms_threshold : 0.45
12+ strides : [8, 16, 32]
13+ imgMean : [ 0, 0, 0 ]
14+ imgStd : [ 1, 1, 1 ]
Original file line number Diff line number Diff line change 1+ #ifndef RTDETR_H
2+ #define RTDETR_H
3+
4+ #include " detection.h"
5+ #include " instance_segmentation.h"
6+
7+ class RTDETR : public Detection {
8+ public:
9+ explicit RTDETR (const YAML::Node &config);
10+ protected:
11+ std::vector<Detections> PostProcess (const std::vector<cv::Mat> &vec_Mat, float *output) override ;
12+ };
13+
14+ #endif
Original file line number Diff line number Diff line change 1+ #include " rtdetr.h"
2+
3+
4+ RTDETR::RTDETR (const YAML::Node &config) : Detection(config) {}
5+
6+ std::vector<Detections> RTDETR::PostProcess (const std::vector<cv::Mat> &imgBatch, float *output) {
7+ std::vector<Detections> vec_result;
8+ int index = 0 ;
9+ auto predSize = bufferSize[1 ] / sizeof (float );
10+ for (const cv::Mat &img : imgBatch)
11+ {
12+ Detections result;
13+ float *pred_per_img = output + index * predSize;
14+ for (int position = 0 ; position < num_rows; position++) {
15+ float *pred_per_obj = pred_per_img + position * (num_classes + 5 );
16+ if (pred_per_obj[4 ] < obj_threshold) continue ;
17+ Box box;
18+ auto max_pos = std::max_element (pred_per_obj + 5 , pred_per_obj + num_classes + 5 );
19+ box.score = pred_per_obj[4 ] * pred_per_obj[max_pos - pred_per_obj];
20+ box.label = max_pos - pred_per_obj - 5 ;
21+
22+ // 将得到的box坐标映射回原图。
23+ auto l = pred_per_obj[0 ] - pred_per_obj[2 ] / 2 ;
24+ auto t = pred_per_obj[1 ] - pred_per_obj[3 ] / 2 ;
25+ auto r = pred_per_obj[0 ] + pred_per_obj[2 ] / 2 ;
26+ auto b = pred_per_obj[1 ] + pred_per_obj[3 ] / 2 ;
27+ auto new_l = dst2src.v0 * l + dst2src.v1 * t + dst2src.v2 ;
28+ auto new_r = dst2src.v0 * r + dst2src.v1 * b + dst2src.v2 ;
29+ auto new_t = dst2src.v3 * l + dst2src.v4 * t + dst2src.v5 ;
30+ auto new_b = dst2src.v3 * r + dst2src.v4 * b + dst2src.v5 ;
31+ box.x = new_l;
32+ box.y = new_t ;
33+ box.w = new_r - new_l;
34+ box.h = new_b - new_t ;
35+
36+ result.dets .emplace_back (box);
37+ }
38+ NMS (result.dets );
39+ vec_result.emplace_back (result);
40+ index++;
41+ }
42+ return vec_result;
43+ }
You can’t perform that action at this time.
0 commit comments