| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef EI_POSTPROCESSING_THRESHOLDS_H |
| #define EI_POSTPROCESSING_THRESHOLDS_H |
|
|
| #include "model-parameters/model_metadata.h" |
| #include "edge-impulse-sdk/classifier/postprocessing/ei_postprocessing_types.h" |
| #include "edge-impulse-sdk/classifier/postprocessing/ei_postprocessing_ai_hub.h" |
| #include "edge-impulse-sdk/classifier/ei_model_types.h" |
| #include "edge-impulse-sdk/classifier/ei_classifier_types.h" |
| #include <string> |
|
|
| #include "edge-impulse-sdk/classifier/postprocessing/ei_postprocessing_common.h" |
|
|
| #if EI_CLASSIFIER_OBJECT_TRACKING_ENABLED == 1 |
| #include "edge-impulse-sdk/classifier/postprocessing/ei_object_tracking.h" |
| #endif |
|
|
| #if EI_CLASSIFIER_CALIBRATION_ENABLED == 1 |
| #include "edge-impulse-sdk/classifier/postprocessing/ei_performance_calibration.h" |
| #endif |
|
|
| |
| |
| |
| |
| |
| |
| EI_IMPULSE_ERROR get_thresholds_postprocessing(const ei_postprocessing_block_t *pp_block, std::vector<ei_threshold_desc_t>& out_thresholds) { |
|
|
| switch (pp_block->type) { |
| case EI_CLASSIFIER_MODE_OBJECT_DETECTION: { |
|
|
| if (pp_block->postprocess_fn == process_paddleocr_f32) { |
| ei_fill_result_paddleocr_f32_config_t *config = (ei_fill_result_paddleocr_f32_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "object_detection", |
| "min_score_pixel", |
| config->min_score_pixel, |
| [config](float v) { |
| config->min_score_pixel = v; |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_detection", |
| "min_score_box", |
| config->min_score_box, |
| [config](float v) { |
| config->min_score_box = v; |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_detection", |
| "unclip_ratio", |
| config->unclip_ratio, |
| [config](float v) { |
| config->unclip_ratio = v; |
| } |
| }); |
| } |
| else if (pp_block->postprocess_fn == process_paddleocr_i8) { |
| ei_fill_result_paddleocr_i8_config_t *config = (ei_fill_result_paddleocr_i8_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "object_detection", |
| "min_score_pixel", |
| config->min_score_pixel, |
| [config](float v) { |
| config->min_score_pixel = v; |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_detection", |
| "min_score_box", |
| config->min_score_box, |
| [config](float v) { |
| config->min_score_box = v; |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_detection", |
| "unclip_ratio", |
| config->unclip_ratio, |
| [config](float v) { |
| config->unclip_ratio = v; |
| } |
| }); |
| } |
| else { |
| ei_fill_result_object_detection_threshold_config_t *config = (ei_fill_result_object_detection_threshold_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "object_detection", |
| "min_score", |
| config->threshold, |
| [config](float v) { |
| config->threshold = v; |
| } |
| }); |
| } |
| break; |
| } |
| case EI_CLASSIFIER_MODE_VISUAL_ANOMALY: { |
| ei_fill_result_visual_ad_f32_config_t *config = (ei_fill_result_visual_ad_f32_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "anomaly_gmm", |
| "min_anomaly_score", |
| config->threshold, |
| [config](float v) { |
| config->threshold = v; |
| } |
| }); |
| break; |
| } |
| } |
|
|
| #if EI_CLASSIFIER_OBJECT_TRACKING_ENABLED == 1 |
| if (pp_block->init_fn == init_object_tracking) { |
| ei_object_tracking_config_t *config = (ei_object_tracking_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "object_tracking", |
| "keep_grace", |
| static_cast<float>(config->keep_grace), |
| [config](float v) { |
| config->keep_grace = static_cast<uint32_t>(v); |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_tracking", |
| "max_observations", |
| static_cast<float>(config->max_observations), |
| [config](float v) { |
| config->max_observations = static_cast<uint16_t>(v); |
| } |
| }); |
| out_thresholds.push_back({ |
| "object_tracking", |
| "threshold", |
| config->threshold, |
| [config](float v) { |
| config->threshold = v; |
| } |
| }); |
| } |
| #endif |
|
|
| #if EI_CLASSIFIER_CALIBRATION_ENABLED == 1 |
| if (pp_block->init_fn == init_perfcal) { |
| ei_performance_calibration_config_t *config = (ei_performance_calibration_config_t*)pp_block->config; |
|
|
| out_thresholds.push_back({ |
| "performance_calibration", |
| "average_window_duration_ms", |
| static_cast<float>(config->average_window_duration_ms), |
| [config](float v) { |
| config->average_window_duration_ms = static_cast<uint32_t>(v); |
| } |
| }); |
| out_thresholds.push_back({ |
| "performance_calibration", |
| "detection_threshold", |
| config->detection_threshold, |
| [config](float v) { |
| config->detection_threshold = v; |
| } |
| }); |
| out_thresholds.push_back({ |
| "performance_calibration", |
| "suppression_ms", |
| static_cast<float>(config->suppression_ms), |
| [config](float v) { |
| config->suppression_ms = static_cast<uint32_t>(v); |
| } |
| }); |
| out_thresholds.push_back({ |
| "performance_calibration", |
| "suppression_flags", |
| static_cast<float>(config->suppression_flags), |
| [config](float v) { |
| config->suppression_flags = static_cast<uint32_t>(v); |
| } |
| }); |
| } |
| #endif |
|
|
| return EI_IMPULSE_OK; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| EI_IMPULSE_ERROR set_threshold_postprocessing(const ei_postprocessing_block_t *pp_block, std::string name, float value) { |
| std::vector<ei_threshold_desc_t> thresholds; |
| EI_IMPULSE_ERROR res = get_thresholds_postprocessing(pp_block, thresholds); |
| if (res != EI_IMPULSE_OK) { |
| return res; |
| } |
|
|
| bool found_threshold = false; |
| for (auto threshold : thresholds) { |
| if (threshold.name != name) continue; |
|
|
| threshold.set_value(value); |
| found_threshold = true; |
| break; |
| } |
|
|
| if (!found_threshold) { |
| return EI_IMPULSE_POSTPROCESSING_THRESHOLD_KEY_NOT_FOUND; |
| } |
|
|
| return EI_IMPULSE_OK; |
| } |
|
|
| #endif |
|
|