Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 06841a8

Browse files
authored
Fix repo sync (#156)
Manual changes necessary: * Update all example and test applications based on changes to the logging and error reporting (for example tensorflow/tflite-micro#1560). Additionally: * Update to latest sync from tflite-micro. * Update to new CMSIS library. bug=Update sync scripts for new cmsis-nn repo #153
1 parent 93e7be8 commit 06841a8

File tree

235 files changed

+8293
-28667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+8293
-28667
lines changed

examples/hello_world/arduino_output_handler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ limitations under the License.
1818
#include "Arduino.h"
1919
#include "constants.h"
2020
#include "output_handler.h"
21+
#include "tensorflow/lite/micro/micro_log.h"
2122

2223
// The pin of the Arduino's built-in LED
2324
int led = LED_BUILTIN;
@@ -26,8 +27,7 @@ int led = LED_BUILTIN;
2627
bool initialized = false;
2728

2829
// Animates a dot across the screen to represent the current x and y values
29-
void HandleOutput(tflite::ErrorReporter* error_reporter, float x_value,
30-
float y_value) {
30+
void HandleOutput(float x_value, float y_value) {
3131
// Do this only once
3232
if (!initialized) {
3333
// Set the LED pin to output
@@ -49,6 +49,6 @@ void HandleOutput(tflite::ErrorReporter* error_reporter, float x_value,
4949
analogWrite(led, brightness_clamped);
5050

5151
// Log the current brightness value for display in the Arduino plotter
52-
TF_LITE_REPORT_ERROR(error_reporter, "%d\n", brightness);
52+
MicroPrintf("%d\n", brightness);
5353
delay(33);
5454
}

examples/hello_world/hello_world.ino

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -15,20 +15,18 @@ limitations under the License.
1515

1616
#include <TensorFlowLite.h>
1717

18-
#include "main_functions.h"
19-
20-
#include "tensorflow/lite/micro/all_ops_resolver.h"
2118
#include "constants.h"
19+
#include "main_functions.h"
2220
#include "model.h"
2321
#include "output_handler.h"
24-
#include "tensorflow/lite/micro/micro_error_reporter.h"
22+
#include "tensorflow/lite/micro/all_ops_resolver.h"
2523
#include "tensorflow/lite/micro/micro_interpreter.h"
24+
#include "tensorflow/lite/micro/micro_log.h"
2625
#include "tensorflow/lite/micro/system_setup.h"
2726
#include "tensorflow/lite/schema/schema_generated.h"
2827

2928
// Globals, used for compatibility with Arduino-style sketches.
3029
namespace {
31-
tflite::ErrorReporter* error_reporter = nullptr;
3230
const tflite::Model* model = nullptr;
3331
tflite::MicroInterpreter* interpreter = nullptr;
3432
TfLiteTensor* input = nullptr;
@@ -43,20 +41,14 @@ uint8_t tensor_arena[kTensorArenaSize];
4341
void setup() {
4442
tflite::InitializeTarget();
4543

46-
// Set up logging. Google style is to avoid globals or statics because of
47-
// lifetime uncertainty, but since this has a trivial destructor it's okay.
48-
// NOLINTNEXTLINE(runtime-global-variables)
49-
static tflite::MicroErrorReporter micro_error_reporter;
50-
error_reporter = &micro_error_reporter;
51-
5244
// Map the model into a usable data structure. This doesn't involve any
5345
// copying or parsing, it's a very lightweight operation.
5446
model = tflite::GetModel(g_model);
5547
if (model->version() != TFLITE_SCHEMA_VERSION) {
56-
TF_LITE_REPORT_ERROR(error_reporter,
57-
"Model provided is schema version %d not equal "
58-
"to supported version %d.",
59-
model->version(), TFLITE_SCHEMA_VERSION);
48+
MicroPrintf(
49+
"Model provided is schema version %d not equal "
50+
"to supported version %d.",
51+
model->version(), TFLITE_SCHEMA_VERSION);
6052
return;
6153
}
6254

@@ -66,13 +58,13 @@ void setup() {
6658

6759
// Build an interpreter to run the model with.
6860
static tflite::MicroInterpreter static_interpreter(
69-
model, resolver, tensor_arena, kTensorArenaSize, error_reporter);
61+
model, resolver, tensor_arena, kTensorArenaSize);
7062
interpreter = &static_interpreter;
7163

7264
// Allocate memory from the tensor_arena for the model's tensors.
7365
TfLiteStatus allocate_status = interpreter->AllocateTensors();
7466
if (allocate_status != kTfLiteOk) {
75-
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
67+
MicroPrintf("AllocateTensors() failed");
7668
return;
7769
}
7870

@@ -102,8 +94,7 @@ void loop() {
10294
// Run inference, and report any error
10395
TfLiteStatus invoke_status = interpreter->Invoke();
10496
if (invoke_status != kTfLiteOk) {
105-
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed on x: %f\n",
106-
static_cast<double>(x));
97+
MicroPrintf("Invoke failed on x: %f\n", static_cast<double>(x));
10798
return;
10899
}
109100

@@ -114,7 +105,7 @@ void loop() {
114105

115106
// Output the results. A custom HandleOutput function can be implemented
116107
// for each supported hardware target.
117-
HandleOutput(error_reporter, x, y);
108+
HandleOutput(x, y);
118109

119110
// Increment the inference_counter, and reset it if we have reached
120111
// the total number per cycle

examples/hello_world/output_handler.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -17,10 +17,8 @@ limitations under the License.
1717
#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_
1818

1919
#include "tensorflow/lite/c/common.h"
20-
#include "tensorflow/lite/micro/micro_error_reporter.h"
2120

2221
// Called by the main loop to produce some output based on the x and y values
23-
void HandleOutput(tflite::ErrorReporter* error_reporter, float x_value,
24-
float y_value);
22+
void HandleOutput(float x_value, float y_value);
2523

2624
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_

examples/magic_wand/magic_wand.ino

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
22
Licensed under the Apache License, Version 2.0 (the "License");
33
you may not use this file except in compliance with the License.
44
You may obtain a copy of the License at
@@ -18,8 +18,8 @@ limitations under the License.
1818

1919
#include "magic_wand_model_data.h"
2020
#include "rasterize_stroke.h"
21-
#include "tensorflow/lite/micro/micro_error_reporter.h"
2221
#include "tensorflow/lite/micro/micro_interpreter.h"
22+
#include "tensorflow/lite/micro/micro_log.h"
2323
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
2424
#include "tensorflow/lite/micro/system_setup.h"
2525
#include "tensorflow/lite/schema/schema_generated.h"
@@ -97,7 +97,6 @@ enum {
9797
constexpr int kTensorArenaSize = 30 * 1024;
9898
uint8_t tensor_arena[kTensorArenaSize];
9999

100-
tflite::ErrorReporter* error_reporter = nullptr;
101100
const tflite::Model* model = nullptr;
102101
tflite::MicroInterpreter* interpreter = nullptr;
103102

@@ -117,13 +116,12 @@ void SetupIMU() {
117116
float rate_frac;
118117
float rate_int;
119118
rate_frac = modf(acceleration_sample_rate, &rate_int);
120-
TF_LITE_REPORT_ERROR(error_reporter, "Acceleration sample rate %d.%d Hz",
121-
static_cast<int32_t>(rate_int),
122-
static_cast<int32_t>(rate_frac * 100));
119+
MicroPrintf("Acceleration sample rate %d.%d Hz",
120+
static_cast<int32_t>(rate_int),
121+
static_cast<int32_t>(rate_frac * 100));
123122
rate_frac = modf(gyroscope_sample_rate, &rate_int);
124-
TF_LITE_REPORT_ERROR(error_reporter, "Gyroscope sample rate %d.%d Hz",
125-
static_cast<int32_t>(rate_int),
126-
static_cast<int32_t>(rate_frac * 100));
123+
MicroPrintf("Gyroscope sample rate %d.%d Hz", static_cast<int32_t>(rate_int),
124+
static_cast<int32_t>(rate_frac * 100));
127125
#endif // MAGIC_WAND_DEBUG
128126
}
129127

@@ -140,7 +138,7 @@ void ReadAccelerometerAndGyroscope(int* new_accelerometer_samples,
140138
// Read each sample, removing it from the device's FIFO buffer
141139
if (!IMU.readGyroscope(current_gyroscope_data[0], current_gyroscope_data[1],
142140
current_gyroscope_data[2])) {
143-
TF_LITE_REPORT_ERROR(error_reporter, "Failed to read gyroscope data");
141+
MicroPrintf("Failed to read gyroscope data");
144142
break;
145143
}
146144
*new_gyroscope_samples += 1;
@@ -153,7 +151,7 @@ void ReadAccelerometerAndGyroscope(int* new_accelerometer_samples,
153151
if (!IMU.readAcceleration(current_acceleration_data[0],
154152
current_acceleration_data[1],
155153
current_acceleration_data[2])) {
156-
TF_LITE_REPORT_ERROR(error_reporter, "Failed to read acceleration data");
154+
MicroPrintf("Failed to read acceleration data");
157155
break;
158156
}
159157
*new_accelerometer_samples += 1;
@@ -366,7 +364,7 @@ void UpdateStroke(int new_samples, bool* done_just_triggered) {
366364
stroke_length = 0;
367365
*stroke_state = eWaiting;
368366
#ifdef MAGIC_WAND_DEBUG
369-
TF_LITE_REPORT_ERROR(error_reporter, "stroke length too small");
367+
MicroPrintf("stroke length too small");
370368
#endif // MAGIC_WAND_DEBUG
371369
}
372370
}
@@ -496,7 +494,7 @@ void UpdateStroke(int new_samples, bool* done_just_triggered) {
496494
*stroke_transmit_length = 0;
497495
stroke_length = 0;
498496
#ifdef MAGIC_WAND_DEBUG
499-
TF_LITE_REPORT_ERROR(error_reporter, "stroke too small");
497+
MicroPrintf("stroke too small");
500498
#endif // MAGIC_WAND_DEBUG
501499
}
502500
}
@@ -508,15 +506,10 @@ void UpdateStroke(int new_samples, bool* done_just_triggered) {
508506
void setup() {
509507
tflite::InitializeTarget(); // setup serial port
510508

511-
// Set up logging. Google style is to avoid globals or statics because of
512-
// lifetime uncertainty, but since this has a trivial destructor it's okay.
513-
static tflite::MicroErrorReporter micro_error_reporter; // NOLINT
514-
error_reporter = &micro_error_reporter;
515-
516-
TF_LITE_REPORT_ERROR(error_reporter, "Started");
509+
MicroPrintf("Started");
517510

518511
if (!IMU.begin()) {
519-
TF_LITE_REPORT_ERROR(error_reporter, "Failed to initialized IMU!");
512+
MicroPrintf("Failed to initialized IMU!");
520513
while (true) {
521514
// NORETURN
522515
}
@@ -525,15 +518,15 @@ void setup() {
525518
SetupIMU();
526519

527520
if (!BLE.begin()) {
528-
TF_LITE_REPORT_ERROR(error_reporter, "Failed to initialized BLE!");
521+
MicroPrintf("Failed to initialized BLE!");
529522
while (true) {
530523
// NORETURN
531524
}
532525
}
533526

534527
String address = BLE.address();
535528

536-
TF_LITE_REPORT_ERROR(error_reporter, "address = %s", address.c_str());
529+
MicroPrintf("address = %s", address.c_str());
537530

538531
address.toUpperCase();
539532

@@ -543,7 +536,7 @@ void setup() {
543536
name += address[address.length() - 2];
544537
name += address[address.length() - 1];
545538

546-
TF_LITE_REPORT_ERROR(error_reporter, "name = %s", name.c_str());
539+
MicroPrintf("name = %s", name.c_str());
547540

548541
BLE.setLocalName(name.c_str());
549542
BLE.setDeviceName(name.c_str());
@@ -559,10 +552,10 @@ void setup() {
559552
// copying or parsing, it's a very lightweight operation.
560553
model = tflite::GetModel(g_magic_wand_model_data);
561554
if (model->version() != TFLITE_SCHEMA_VERSION) {
562-
TF_LITE_REPORT_ERROR(error_reporter,
563-
"Model provided is schema version %d not equal "
564-
"to supported version %d.",
565-
model->version(), TFLITE_SCHEMA_VERSION);
555+
MicroPrintf(
556+
"Model provided is schema version %d not equal "
557+
"to supported version %d.",
558+
model->version(), TFLITE_SCHEMA_VERSION);
566559
return;
567560
}
568561

@@ -579,7 +572,7 @@ void setup() {
579572

580573
// Build an interpreter to run the model with.
581574
static tflite::MicroInterpreter static_interpreter(
582-
model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter);
575+
model, micro_op_resolver, tensor_arena, kTensorArenaSize);
583576
interpreter = &static_interpreter;
584577

585578
// Allocate memory from the tensor_arena for the model's tensors.
@@ -593,17 +586,15 @@ void setup() {
593586
(model_input->type != kTfLiteInt8) ||
594587
(model_input->params.zero_point != -128) ||
595588
(model_input->params.scale != 1.0)) {
596-
TF_LITE_REPORT_ERROR(error_reporter,
597-
"Bad input tensor parameters in model");
589+
MicroPrintf("Bad input tensor parameters in model");
598590
return;
599591
}
600592

601593
TfLiteTensor* model_output = interpreter->output(0);
602594
if ((model_output->dims->size != 2) || (model_output->dims->data[0] != 1) ||
603595
(model_output->dims->data[1] != label_count) ||
604596
(model_output->type != kTfLiteInt8)) {
605-
TF_LITE_REPORT_ERROR(error_reporter,
606-
"Bad output tensor parameters in model");
597+
MicroPrintf("Bad output tensor parameters in model");
607598
return;
608599
}
609600
}
@@ -615,8 +606,7 @@ void loop() {
615606
static bool was_connected_last = false;
616607
if (central && !was_connected_last) {
617608
// print the central's BT address:
618-
TF_LITE_REPORT_ERROR(error_reporter, "Connected to central: %s",
619-
central.address().c_str());
609+
MicroPrintf("Connected to central: %s", central.address().c_str());
620610
}
621611
was_connected_last = central;
622612

@@ -669,10 +659,10 @@ void loop() {
669659
line[x] = output;
670660
}
671661
line[raster_width] = 0;
672-
TF_LITE_REPORT_ERROR(error_reporter, line);
662+
MicroPrintf(line);
673663
}
674664
#ifdef MAGIC_WAND_DEBUG
675-
TF_LITE_REPORT_ERROR(error_reporter, "tx len: %d", *stroke_transmit_length);
665+
MicroPrintf("tx len: %d", *stroke_transmit_length);
676666
#endif // MAGIC_WAND_DEBUG
677667

678668
TfLiteTensor* model_input = interpreter->input(0);
@@ -682,7 +672,7 @@ void loop() {
682672

683673
TfLiteStatus invoke_status = interpreter->Invoke();
684674
if (invoke_status != kTfLiteOk) {
685-
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed");
675+
MicroPrintf("Invoke failed");
686676
return;
687677
}
688678

@@ -701,8 +691,8 @@ void loop() {
701691
(max_score - output->params.zero_point) * output->params.scale;
702692
float max_score_int;
703693
float max_score_frac = modf(max_score_f * 100, &max_score_int);
704-
TF_LITE_REPORT_ERROR(error_reporter, "Found %s (%d.%d%%)",
705-
labels[max_index], static_cast<int>(max_score_int),
706-
static_cast<int>(max_score_frac * 100));
694+
MicroPrintf("Found %s (%d.%d%%)", labels[max_index],
695+
static_cast<int>(max_score_int),
696+
static_cast<int>(max_score_frac * 100));
707697
}
708698
}

0 commit comments

Comments
 (0)