| 23 | #include "tensorflow/lite/version.h" |
| 24 | |
| 25 | int main(int argc, char* argv[]) { |
| 26 | // Set up logging |
| 27 | tflite::MicroErrorReporter micro_error_reporter; |
| 28 | tflite::ErrorReporter* error_reporter = µ_error_reporter; |
| 29 | |
| 30 | // Map the model into a usable data structure. This doesn't involve any |
| 31 | // copying or parsing, it's a very lightweight operation. |
| 32 | const tflite::Model* model = ::tflite::GetModel(g_sine_model_data); |
| 33 | if (model->version() != TFLITE_SCHEMA_VERSION) { |
| 34 | error_reporter->Report( |
| 35 | "Model provided is schema version %d not equal " |
| 36 | "to supported version %d.\n", |
| 37 | model->version(), TFLITE_SCHEMA_VERSION); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | // This pulls in all the operation implementations we need |
| 42 | tflite::ops::micro::AllOpsResolver resolver; |
| 43 | |
| 44 | // Create an area of memory to use for input, output, and intermediate arrays. |
| 45 | // Finding the minimum value for your model may require some trial and error. |
| 46 | const int tensor_arena_size = 2 * 1024; |
| 47 | uint8_t tensor_arena[tensor_arena_size]; |
| 48 | |
| 49 | // Build an interpreter to run the model with |
| 50 | tflite::MicroInterpreter interpreter(model, resolver, tensor_arena, |
| 51 | tensor_arena_size, error_reporter); |
| 52 | |
| 53 | // Allocate memory from the tensor_arena for the model's tensors |
| 54 | interpreter.AllocateTensors(); |
| 55 | |
| 56 | // Obtain pointers to the model's input and output tensors |
| 57 | TfLiteTensor* input = interpreter.input(0); |
| 58 | TfLiteTensor* output = interpreter.output(0); |
| 59 | |
| 60 | // Keep track of how many inferences we have performed |
| 61 | int inference_count = 0; |
| 62 | |
| 63 | // Loop indefinitely |
| 64 | while (true) { |
| 65 | // Calculate an x value to feed into the model. We compare the current |
| 66 | // inference_count to the number of inferences per cycle to determine |
| 67 | // our position within the range of possible x values the model was |
| 68 | // trained on, and use this to calculate a value. |
| 69 | float position = static_cast<float>(inference_count) / |
| 70 | static_cast<float>(kInferencesPerCycle); |
| 71 | float x_val = position * kXrange; |
| 72 | |
| 73 | // Place our calculated x value in the model's input tensor |
| 74 | input->data.f[0] = x_val; |
| 75 | |
| 76 | // Run inference, and report any error |
| 77 | TfLiteStatus invoke_status = interpreter.Invoke(); |
| 78 | if (invoke_status != kTfLiteOk) { |
| 79 | error_reporter->Report("Invoke failed on x_val: %f\n", |
| 80 | static_cast<double>(x_val)); |
| 81 | continue; |
| 82 | } |
nothing calls this directly
no test coverage detected