9
9
#include " tensorflow/lite/micro/cortex_m_generic/debug_log_callback.h"
10
10
#include " tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h"
11
11
#include " tensorflow/lite/micro/micro_interpreter.h"
12
- #include " tensorflow/lite/schema/schema_utils.h"
13
12
14
13
#include " libtf.h"
15
14
#define LIBTF_MAX_OPS 80
16
15
17
16
extern " C" {
18
- // These are set by openmv py_tf.c code to redirect printing to an error message buffer...
19
- char *py_tf_putchar_buffer = NULL ;
20
- size_t py_tf_putchar_buffer_index = 0 ;
21
- size_t py_tf_putchar_buffer_len = 0 ;
22
-
23
- static void libtf_debug_log (const char *s) {
24
- for (size_t i = 0 , j = strlen (s); i < j; i++) {
25
- if (py_tf_putchar_buffer_len) {
26
- py_tf_putchar_buffer[py_tf_putchar_buffer_index++] = s[i];
27
- py_tf_putchar_buffer_len--;
28
- } else {
29
- putchar (s[i]);
30
- }
31
- }
17
+ // Default log handler.
18
+ __attribute__ ((weak)) void libtf_log_handler(const char *s) {
19
+ printf (s);
32
20
}
33
21
34
22
static int libtf_align_tensor_arena (unsigned char **tensor_arena, size_t *tensor_arena_size) {
@@ -240,24 +228,11 @@ extern "C" {
240
228
resolver.AddZerosLike ();
241
229
}
242
230
243
- static uint32_t libtf_ops_hash (const tflite::Model *model) {
244
- uint32_t hash = 5381 ;
245
- const auto *subgraph = model->subgraphs ()->Get (0 );
246
- for (size_t i = 0 ; i < subgraph->operators ()->size (); i++) {
247
- const auto *op = subgraph->operators ()->Get (i);
248
- uint32_t opcode = GetBuiltinCode (model->operator_codes ()->Get (op->opcode_index ()));
249
- for (size_t x=0 ; x<4 ; x++) {
250
- hash = ((hash << 5 ) + hash) + ((uint8_t *) &opcode)[x];
251
- }
252
- }
253
- return hash;
254
- }
255
-
256
231
static int libtf_get_parameters (const unsigned char *model_data,
257
232
unsigned char *tensor_arena, size_t tensor_arena_size,
258
233
libtf_parameters_t *params,
259
234
libtf_resolver_init_t libtf_resolver_init) {
260
- RegisterDebugLogCallback (libtf_debug_log );
235
+ RegisterDebugLogCallback (libtf_log_handler );
261
236
262
237
tflite::MicroErrorReporter micro_error_reporter;
263
238
tflite::ErrorReporter *error_reporter = µ_error_reporter;
@@ -278,8 +253,6 @@ extern "C" {
278
253
libtf_resolver_init (resolver);
279
254
280
255
tflite::MicroInterpreter interpreter (model, resolver, tensor_arena, tensor_arena_size, error_reporter);
281
- params->operators_size = interpreter.operators_size ();
282
- params->operators_hash = libtf_ops_hash (model);
283
256
284
257
if (interpreter.AllocateTensors () != kTfLiteOk ) {
285
258
error_reporter->Report (" AllocateTensors() failed!" );
@@ -426,7 +399,7 @@ extern "C" {
426
399
libtf_output_data_callback_t output_callback,
427
400
void *output_callback_data,
428
401
libtf_resolver_init_t libtf_resolver_init) {
429
- RegisterDebugLogCallback (libtf_debug_log );
402
+ RegisterDebugLogCallback (libtf_log_handler );
430
403
431
404
tflite::MicroErrorReporter micro_error_reporter;
432
405
tflite::ErrorReporter *error_reporter = µ_error_reporter;
@@ -502,7 +475,7 @@ extern "C" {
502
475
}
503
476
504
477
int libtf_initialize_micro_features () {
505
- RegisterDebugLogCallback (libtf_debug_log );
478
+ RegisterDebugLogCallback (libtf_log_handler );
506
479
507
480
tflite::MicroErrorReporter micro_error_reporter;
508
481
tflite::ErrorReporter *error_reporter = µ_error_reporter;
@@ -516,7 +489,7 @@ extern "C" {
516
489
517
490
int libtf_generate_micro_features (const int16_t *input, int input_size,
518
491
int output_size, int8_t *output, size_t *num_samples_read) {
519
- RegisterDebugLogCallback (libtf_debug_log );
492
+ RegisterDebugLogCallback (libtf_log_handler );
520
493
521
494
tflite::MicroErrorReporter micro_error_reporter;
522
495
tflite::ErrorReporter *error_reporter = µ_error_reporter;
0 commit comments