18 #ifndef CONFIG_PARSER_H
19 #define CONFIG_PARSER_H
22 #include <unordered_map>
24 #include <yaml-cpp/yaml.h>
32 ConfigParser(
const std::string& configPath =
"./config.yaml");
35 bool loadConfig(
const std::string& configPath);
38 std::string
getString(
const std::string& key,
const std::string& defaultValue =
"")
const;
41 int getInt(
const std::string& key,
int defaultValue = 0)
const;
44 float getFloat(
const std::string& key,
float defaultValue = 0.0f)
const;
47 bool getBool(
const std::string& key,
bool defaultValue =
false)
const;
50 bool hasKey(
const std::string& key)
const;
64 std::cout <<
"No configuration loaded." << std::endl;
68 const int prop_width = 35;
69 const int val_width = 80;
70 const int table_width = prop_width + val_width + 5;
73 auto separator = [prop_width, val_width]() {
74 std::string sep =
"+ ";
75 sep += std::string(prop_width,
'-');
77 sep += std::string(val_width,
'-');
83 std::cout << separator() << std::endl;
85 std::cout << std::setw(table_width - 2) << std::left <<
"Configuration Properties (" + m_ConfigPath +
")";
86 std::cout <<
" │" << std::endl;
87 std::cout << separator() << std::endl;
91 std::cout << std::setw(prop_width) << std::left <<
"Property";
93 std::cout << std::setw(val_width) << std::left <<
"Value";
94 std::cout <<
" │" << std::endl;
97 std::cout << separator() << std::endl;
98 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"onnx_file"
99 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
onnx_file
100 <<
" │" << std::endl;
102 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"engine_file"
103 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
engine_file
104 <<
" │" << std::endl;
106 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"labels_file"
107 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
labels_file
108 <<
" │" << std::endl;
110 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"gpu_id"
111 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
gpu_id
112 <<
" │" << std::endl;
114 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"batch_size"
115 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
batch_size
116 <<
" │" << std::endl;
118 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"num_sensors"
119 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
num_sensors
120 <<
" │" << std::endl;
122 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"enable_fp16"
123 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
enable_fp16 ?
"true" :
"false")
124 <<
" │" << std::endl;
126 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"force_engine_rebuild"
127 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
force_engine_rebuild ?
"true" :
"false")
128 <<
" │" << std::endl;
130 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"partial_batch"
131 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
partial_batch ?
"true" :
"false")
132 <<
" │" << std::endl;
134 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"feedback"
135 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
feedback ?
"true" :
"false")
136 <<
" │" << std::endl;
138 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"interval"
139 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
interval
140 <<
" │" << std::endl;
143 std::cout << separator() << std::endl;
144 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"calib_file_path"
145 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
calib_file_path
146 <<
" │" << std::endl;
148 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"bev_group_name"
149 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
bev_group_name
150 <<
" │" << std::endl;
152 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"calib_mode"
153 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
calib_mode
154 <<
" │" << std::endl;
156 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"use_camera_groups"
157 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
use_camera_groups ?
"true" :
"false")
158 <<
" │" << std::endl;
160 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"recentering"
161 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
recentering ?
"true" :
"false")
162 <<
" │" << std::endl;
165 std::cout << separator() << std::endl;
166 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"preprocessed_height"
168 <<
" │" << std::endl;
170 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"preprocessed_width"
172 <<
" │" << std::endl;
174 auto vector_to_string = [](
const std::vector<int>& vec) {
175 std::stringstream ss;
177 for (
size_t i = 0; i < vec.size(); ++i) {
179 if (i < vec.size() - 1) ss <<
", ";
185 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.resize"
186 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
aug_config.
resize
187 <<
" │" << std::endl;
189 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.resize_dims"
190 <<
" │ " << std::setw(val_width) << std::left << vector_to_string(m_Properties.
aug_config.
resize_dims)
191 <<
" │" << std::endl;
193 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.crop"
194 <<
" │ " << std::setw(val_width) << std::left << vector_to_string(m_Properties.
aug_config.
crop)
195 <<
" │" << std::endl;
197 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.flip"
198 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
aug_config.
flip ?
"true" :
"false")
199 <<
" │" << std::endl;
201 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.rotate"
202 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
aug_config.
rotate
203 <<
" │" << std::endl;
205 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"aug_config.rotate_3d"
207 <<
" │" << std::endl;
211 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"num_anchor"
212 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
num_anchor
213 <<
" │" << std::endl;
215 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"embed_dims"
216 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
embed_dims
217 <<
" │" << std::endl;
219 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"anchor"
220 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
anchor
221 <<
" │" << std::endl;
223 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"anchor_handler"
224 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
anchor_handler
225 <<
" │" << std::endl;
227 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"num_temp_instances"
229 <<
" │" << std::endl;
231 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"default_time_interval"
233 <<
" │" << std::endl;
235 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"confidence_decay"
236 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
confidence_decay
237 <<
" │" << std::endl;
239 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"anchor_grad"
240 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
anchor_grad ?
"true" :
"false")
241 <<
" │" << std::endl;
243 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"feat_grad"
244 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
feat_grad ?
"true" :
"false")
245 <<
" │" << std::endl;
247 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"max_time_interval"
249 <<
" │" << std::endl;
251 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"reid_dims"
252 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
reid_dims
253 <<
" │" << std::endl;
255 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"num_output"
256 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
num_output
257 <<
" │" << std::endl;
259 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"score_threshold"
260 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
score_threshold
261 <<
" │" << std::endl;
263 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"num_torch_threads"
265 <<
" │" << std::endl;
267 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"generate_3d_bbox"
268 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
generate_3d_bbox ?
"true" :
"false")
269 <<
" │" << std::endl;
271 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"generate_2d_bbox"
272 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
generate_2d_bbox ?
"true" :
"false")
273 <<
" │" << std::endl;
275 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"bbox_color_mode"
276 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
bbox_color_mode
277 <<
" │" << std::endl;
279 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_class_labels"
280 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_class_labels ?
"true" :
"false")
281 <<
" │" << std::endl;
283 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_instance_ids"
284 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_instance_ids ?
"true" :
"false")
285 <<
" │" << std::endl;
287 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_class_score"
288 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_class_score ?
"true" :
"false")
289 <<
" │" << std::endl;
290 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_3d_bbox"
291 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_3d_bbox ?
"true" :
"false")
292 <<
" │" << std::endl;
293 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_2d_bbox"
294 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_2d_bbox ?
"true" :
"false")
295 <<
" │" << std::endl;
298 std::cout << separator() << std::endl;
299 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"log_level"
300 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
log_level
301 <<
" │" << std::endl;
303 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_partial_batch_info"
305 <<
" │" << std::endl;
307 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_tensor_info"
308 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
display_tensor_info ?
"true" :
"false")
309 <<
" │" << std::endl;
311 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"display_bbox_list_info"
313 <<
" │" << std::endl;
315 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"max_objects_to_display"
317 <<
" │" << std::endl;
319 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"dump_frames"
320 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
dump_frames ?
"true" :
"false")
321 <<
" │" << std::endl;
323 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"dump_max_frames"
324 <<
" │ " << std::setw(val_width) << std::left << m_Properties.
dump_max_frames
325 <<
" │" << std::endl;
327 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"fixed_input_tensor_path"
329 <<
" │" << std::endl;
331 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"gpu_postprocess"
332 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
gpu_postprocess ?
"true" :
"false")
333 <<
" │" << std::endl;
335 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"use_static_frame_num"
336 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
use_static_frame_num ?
"true" :
"false")
337 <<
" │" << std::endl;
339 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"trt_logger_severity"
341 <<
" │" << std::endl;
343 std::cout <<
"│ " << std::setw(prop_width) << std::left <<
"enable_profiler"
344 <<
" │ " << std::setw(val_width) << std::left << (m_Properties.
enable_profiler ?
"true" :
"false")
345 <<
" │" << std::endl;
348 std::cout << separator() << std::endl;
353 void updatePropertiesFromConfig();
355 std::string m_ConfigPath;
361 #endif // CONFIG_PARSER_H