Skip to content

Commit 9f418f0

Browse files
committed
postprocessing: hailo: Using single filtering call for NMS/non-NMS networks
The v4.18 Hailo release combines the cases for both types of postprocessing. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 87974bf commit 9f418f0

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

post_processing_stages/hailo/hailo_yolo_inference.cpp

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#include "hailo_postprocessing_stage.hpp"
2525

2626
using Size = libcamera::Size;
27-
using PostProcFuncPtr = void (*)(HailoROIPtr, YoloParams *);
28-
using PostProcFuncPtrNms = void (*)(HailoROIPtr);
27+
using PostProcFuncPtrNms = void (*)(HailoROIPtr, YoloParams *);
2928
using InitFuncPtr = YoloParams *(*)(std::string, std::string);
3029
using FreeFuncPtr = void (*)(void *);
3130

@@ -34,7 +33,6 @@ using Rectangle = libcamera::Rectangle;
3433
namespace fs = std::filesystem;
3534

3635
#define NAME "hailo_yolo_inference"
37-
#define POSTPROC_LIB "libyolo_post.so"
3836
#define POSTPROC_LIB_NMS "libyolo_hailortpp_post.so"
3937

4038
class YoloInference : public HailoPostProcessingStage
@@ -65,7 +63,6 @@ class YoloInference : public HailoPostProcessingStage
6563

6664
std::vector<LtObject> lt_objects_;
6765
std::mutex lock_;
68-
PostProcessingLib postproc_;
6966
PostProcessingLib postproc_nms_;
7067
YoloParams *yolo_params_ = nullptr;
7168

@@ -82,16 +79,15 @@ class YoloInference : public HailoPostProcessingStage
8279
};
8380

8481
YoloInference::YoloInference(RPiCamApp *app)
85-
: HailoPostProcessingStage(app), postproc_(PostProcLibDir(POSTPROC_LIB)),
86-
postproc_nms_(PostProcLibDir(POSTPROC_LIB_NMS))
82+
: HailoPostProcessingStage(app), postproc_nms_(PostProcLibDir(POSTPROC_LIB_NMS))
8783
{
8884
}
8985

9086
YoloInference::~YoloInference()
9187
{
9288
if (yolo_params_)
9389
{
94-
FreeFuncPtr free_func = reinterpret_cast<FreeFuncPtr>(postproc_.GetSymbol("free_resources"));
90+
FreeFuncPtr free_func = reinterpret_cast<FreeFuncPtr>(postproc_nms_.GetSymbol("free_resources"));
9591
if (free_func)
9692
free_func(yolo_params_);
9793
}
@@ -118,14 +114,14 @@ void YoloInference::Read(boost::property_tree::ptree const &params)
118114
else
119115
temporal_filtering_ = false;
120116

121-
InitFuncPtr init = reinterpret_cast<InitFuncPtr>(postproc_.GetSymbol("init"));
122-
const std::string config_file = params.get<std::string>("hailopp_config_file", "");
123-
if (init && !config_file.empty())
117+
InitFuncPtr init = reinterpret_cast<InitFuncPtr>(postproc_nms_.GetSymbol("init"));
118+
const std::string config_file = params.get<std::string>("hailopp_config_file", {});
119+
if (!config_file.empty())
124120
{
125121
if (!fs::exists(config_file))
126122
throw std::runtime_error(std::string("hailo postprocess config file not found: ") + config_file);
127-
yolo_params_ = init(config_file, "");
128123
}
124+
yolo_params_ = init(config_file, "");
129125

130126
HailoPostProcessingStage::Read(params);
131127
}
@@ -238,12 +234,8 @@ std::vector<Detection> YoloInference::runInference(const uint8_t *frame, const s
238234
{
239235
hailort::AsyncInferJob job;
240236
std::vector<OutTensor> output_tensors;
241-
bool nms_on_hailo = false;
242237
hailo_status status;
243238

244-
if (infer_model_->outputs().size() == 1 && infer_model_->outputs()[0].is_nms())
245-
nms_on_hailo = true;
246-
247239
status = HailoPostProcessingStage::DispatchJob(frame, job, output_tensors);
248240
if (status != HAILO_SUCCESS)
249241
return {};
@@ -260,24 +252,9 @@ std::vector<Detection> YoloInference::runInference(const uint8_t *frame, const s
260252
}
261253

262254
HailoROIPtr roi = MakeROI(output_tensors);
255+
PostProcFuncPtrNms filter = reinterpret_cast<PostProcFuncPtrNms>(postproc_nms_.GetSymbol("filter"));
263256

264-
if (nms_on_hailo)
265-
{
266-
PostProcFuncPtrNms filter = reinterpret_cast<PostProcFuncPtrNms>(postproc_nms_.GetSymbol("filter"));
267-
if (!filter)
268-
return {};
269-
270-
filter(roi);
271-
}
272-
else
273-
{
274-
PostProcFuncPtr filter = reinterpret_cast<PostProcFuncPtr>(postproc_.GetSymbol("filter"));
275-
if (!filter)
276-
return {};
277-
278-
filter(roi, yolo_params_);
279-
}
280-
257+
filter(roi, yolo_params_);
281258
std::vector<HailoDetectionPtr> detections = hailo_common::get_hailo_detections(roi);
282259

283260
LOG(2, "------");

post_processing_stages/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ endif
101101

102102
# Hailo postprocessing stages.
103103
enable_hailo = false
104-
hailort_dep = dependency('HailoRT', modules : ['HailoRT::libhailort'], version: '>=4.17.0',
104+
hailort_dep = dependency('HailoRT', modules : ['HailoRT::libhailort'], version: '>=4.18.0',
105105
required : get_option('enable_hailo'))
106106
hailo_tappas_dep = dependency('hailo-tappas-core', required : get_option('enable_hailo'))
107107
if hailort_dep.found() and hailo_tappas_dep.found()

0 commit comments

Comments
 (0)