Merge pull request #1540 from openmv/tf_fix_output

py_tf.c: Fix output scaling for uint8/int8.
This commit is contained in:
Ibrahim Abdelkader 2022-02-17 21:41:01 +02:00 committed by GitHub
commit f7f0b80418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -1,2 +1,2 @@
person
no_person
person

View File

@ -21,7 +21,6 @@
#include "ff_wrapper.h"
#include "py_tf.h"
#include "libtf_builtin_models.h"
#define GRAYSCALE_RANGE ((COLOR_GRAYSCALE_MAX) - (COLOR_GRAYSCALE_MIN))
#define GRAYSCALE_MID (((GRAYSCALE_RANGE) + 1) / 2)
@ -391,10 +390,15 @@ STATIC void py_tf_classify_output_data_callback(void *callback_data,
((mp_obj_list_t *) arg->out)->items[i] =
mp_obj_new_float(((float *) model_output)[i]);
}
} else if (params->output_datatype == LIBTF_DATATYPE_INT8) {
for (int i = 0, ii = params->output_channels; i < ii; i++) {
((mp_obj_list_t *) arg->out)->items[i] =
mp_obj_new_float( ((float) (((int8_t *) model_output)[i] - params->output_zero_point)) * params->output_scale);
}
} else {
for (int i = 0, ii = params->output_channels; i < ii; i++) {
((mp_obj_list_t *) arg->out)->items[i] =
mp_obj_new_float((((uint8_t *) model_output)[i] - params->output_zero_point) * params->output_scale);
mp_obj_new_float( ((float) (((uint8_t *) model_output)[i] - params->output_zero_point)) * params->output_scale);
}
}
}