Apollo 11.0
自动驾驶开放平台
traffic_light_detection_yolox.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#pragma once
18
19#include <map>
20#include <memory>
21#include <numeric>
22#include <string>
23#include <vector>
24
25#include "modules/perception/traffic_light_detection/detector/yolox_detection/proto/model_param.pb.h"
26
36
37namespace apollo {
38namespace perception {
39namespace trafficlight {
40
42 int left_pad = 0;
43 int right_pad = 0;
44 int top_pad = 0;
45 int bottom_pad = 0;
46 int roi_width = 0;
47 int roi_height = 0;
48 int roi_x = 0;
49 int roi_y = 0;
50 float scale = 1.f;
52 int l_pad = 0,
53 int r_pad = 0,
54 int t_pad = 0,
55 int b_pad = 0,
56 int r_w = 0,
57 int r_h = 0,
58 float s = 1.f,
59 int r_x = 0,
60 int r_y = 0) {
61 left_pad = l_pad;
62 right_pad = r_pad;
63 top_pad = t_pad;
64 bottom_pad = b_pad;
65 roi_width = r_w;
66 roi_height = r_h;
67 scale = s;
68 roi_x = r_x;
69 roi_y = r_y;
70 }
71 void Reset() {
72 left_pad = 0;
73 right_pad = 0;
74 top_pad = 0;
75 bottom_pad = 0;
76 roi_width = 0;
77 roi_height = 0;
78 scale = 1.f;
79 roi_x = 0;
80 roi_y = 0;
81 }
82};
83
85public:
87
89
90 bool Init(const TrafficLightDetectorInitOptions& options) override;
91
92 bool Detect(camera::TrafficLightFrame* frame) override;
93
95
96 const std::vector<base::TrafficLightPtr>& getDetectedBoxes() {
97 return detected_bboxes_;
98 }
99
100private:
101 bool DetectHeadByModel(camera::TrafficLightFrame* frame);
102
103 // work function
104 bool DetectTL(camera::TrafficLightFrame* frame);
105
106 bool GetCandidateHeads(
107 const int batch_id,
108 std::vector<base::TrafficLightPtr>* lights,
109 std::vector<base::TrafficLightPtr>& lights_ref);
110
111 void AddShapeYolox(
112 std::map<std::string, std::vector<int>>* shape_map,
113 const google::protobuf::RepeatedPtrField<common::ModelBlob>& model_blobs);
114 void ApplyNMS(std::vector<base::TrafficLightPtr>* lights);
115 void ApplyOverlapNMS(std::vector<base::TrafficLightPtr>* lights);
116 void NMS(std::vector<base::TrafficLightPtr>* lights, const std::string camera_name);
117
118private:
119 std::shared_ptr<inference::Inference> detect_net_ = nullptr;
120 std::map<std::string, std::vector<base::TrafficLightPtr>> detected_heads_;
121 std::vector<std::string> input_names_;
122 std::vector<std::string> output_names_;
123 float cls_th_ = 0.01;
124 int resize_height_ = 640;
125 int resize_width_ = 640;
126 // vertical_light, quadrate_light, horizontal_light
127 int tl_shape_classes_ = 3;
128 int min_head_area_ = 10;
129 int max_batch_roi_ = 3000;
130
131 camera::DataProvider::ImageOptions data_provider_image_option_;
132 // traffic light detection params
133 trafficlight::yolox::ModelParam detection_param_;
134 std::vector<base::TrafficLightPtr> detected_bboxes_;
135 std::vector<std::string> bbox_project_camera_;
136 std::vector<std::string> detected_light_ids_;
137 int max_batch_size_ = 4;
138 int param_blob_length_ = 6;
139 std::vector<float> mean_ = {0, 0, 0};
140 std::vector<PadResizeParam> pad_resize_params_;
141 base::Image8U padding_image_container_;
142 int gpu_id_ = 0;
143 Select select_;
144
145 std::shared_ptr<IGetBox> crop_;
146 cudaStream_t stream_ = 0;
147
149};
150
151} // namespace trafficlight
152} // namespace perception
153} // namespace apollo
A wrapper around Blob holders serving as the basic computational unit for images.
Definition image_8u.h:44
bool Detect(camera::TrafficLightFrame *frame) override
Detect traffic light from image.
bool Init(const TrafficLightDetectorInitOptions &options) override
Initialize traffic light detector parameters.
bool Inference(camera::TrafficLightFrame *frame)
#define DISALLOW_COPY_AND_ASSIGN(classname)
Definition macros.h:48
class register implement
Definition arena_queue.h:37
PadResizeParam(int l_pad=0, int r_pad=0, int t_pad=0, int b_pad=0, int r_w=0, int r_h=0, float s=1.f, int r_x=0, int r_y=0)