Sine wave predictor
This document provides a guide to using Consentium's TinyML library for a continuous sine function inference example. This example uses TensorFlow Lite Micro with an Edge board compatible with ESP32/Raspberry Pi Pico W.
Overview
This example demonstrates how to perform continuous inference on a sine function using a TensorFlow Lite model. The model predicts the sine value for a given input ( x ), and the results are compared with the actual sine value calculated using the sin function.
Prerequisites
Hardware: ESP32 or Raspberry Pi Pico W compatible Edge board.
Software: Consentium's TinyML library, EdgeNeuron library, TensorFlow Lite Micro.
Code Explanation
Includes and Constants
#include <EdgeNeuron.h>
#include "model.h"
// Tensor arena for TensorFlow Lite to store tensors
constexpr int kTensorArenaSize = 2000;
alignas(16) uint8_t tensor_arena[kTensorArenaSize];EdgeNeuron.h: Include the EdgeNeuron library.model.h: Include the header file for the TensorFlow Lite model.tensor_arena: Defines the memory arena for TensorFlow Lite to manage tensor allocations.
Global Variables
x: The input value for the sine function.step: The increment value forxin each loop iteration.
Setup Function
Initializes the serial communication.
Prints initialization messages.
Calls
initializeModel()to load and set up the TensorFlow Lite model.
Loop Function
Resets
xto 0 if it exceeds (2\pi).Sets the input value
xin the model.Runs the inference and retrieves the output.
Calculates and prints both the predicted and actual sine values.
Increments
xand includes a delay to make the output readable.
License
This code is licensed under the MIT license. All text in the license header must be included in any redistribution.
Last updated