Skip to content

Commit

Permalink
fix: calculate scale when resolution changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr committed Jul 22, 2024
1 parent f3346be commit dc4d7b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions core/algorithm/el_algorithm_yolo_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ inline void AlgorithmYOLOWorld::init() {
_output_quant_params[i] = this->__p_engine->get_output_quant_param(i);
}

_scaled_strides.reserve(_anchor_strides.size());
for (const auto& anchor_stride : _anchor_strides) {
_scaled_strides.emplace_back(std::make_pair(static_cast<float>(anchor_stride.stride) * _w_scale,
static_cast<float>(anchor_stride.stride) * _h_scale));
}

for (size_t i = 0; i < _outputs; ++i) {
// assuimg all outputs has 3 dims and the first dim is 1 (actual validation is done in is_model_valid)
auto dim_1 = _output_shapes[i].dims[1];
Expand Down Expand Up @@ -288,8 +282,20 @@ inline void AlgorithmYOLOWorld::init() {
}

el_err_code_t AlgorithmYOLOWorld::run(ImageType* input) {
_w_scale = static_cast<float>(input->width) / static_cast<float>(_input_img.width);
_h_scale = static_cast<float>(input->height) / static_cast<float>(_input_img.height);
auto w_scale = static_cast<float>(input->width) / static_cast<float>(_input_img.width);
auto h_scale = static_cast<float>(input->height) / static_cast<float>(_input_img.height);

if (w_scale != _w_scale || h_scale != _h_scale) [[unlikely]] {
_w_scale = w_scale;
_h_scale = h_scale;

_scaled_strides.resize(_anchor_strides.size());
size_t i = 0;
for (const auto& anchor_stride : _anchor_strides) {
const auto s = static_cast<float>(anchor_stride.stride);
_scaled_strides[i++] = std::make_pair(s * _w_scale, s * _h_scale);
}
}

// TODO: image type conversion before underlying_run, because underlying_run doing a type erasure
return underlying_run(input);
Expand Down
2 changes: 1 addition & 1 deletion porting/himax/we2/el_config_porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#endif
#endif

#define CONFIG_EL_DEBUG 0 // use 0 to make firmware generator happy
#define CONFIG_EL_DEBUG 1 // use 1 to make firmware generator happy
#define CONFIG_EL_DEBUG_COLOR 0
#define CONFIG_EL_HAS_FREERTOS_SUPPORT 1
#define SSCMA_REPL_EXECUTOR_PRIO 2
Expand Down

0 comments on commit dc4d7b6

Please sign in to comment.