### LSTM Time-Series Classification with Eloquent TinyML Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt This example demonstrates end-to-end classification of accelerometer gestures using an LSTM model. It requires including the model header, TFLM ESP32 runtime, and Eloquent TinyML. The model is configured in `setup()` and predictions are made in `loop()`. ```cpp #include #include "tfModel.h" // LSTM model header (defines TF_NUM_INPUTS, TF_NUM_OUTPUTS, TF_NUM_OPS) #include #include #define ARENA_SIZE 30000 Eloquent::TF::Sequential tf; // Sample input: 150 timesteps × 3 axes = 450 floats per gesture float idle[450] = { /* ... accelerometer data ... */ }; float horizontal[450] = { /* ... accelerometer data ... */ }; float vertical[450] = { /* ... accelerometer data ... */ }; void predictAndPrint(const char* label, float* input, uint8_t expectedClass) { if (!tf.predict(input).isOk()) { Serial.print("Error: "); Serial.println(tf.exception.toString()); return; } Serial.print("Sample '" ); Serial.print(label); Serial.print("': expected="); Serial.print(expectedClass); Serial.print(", predicted="); Serial.println(tf.classification); } void setup() { Serial.begin(115200); delay(3000); Serial.println("__TENSORFLOW LSTM__"); tf.setNumInputs(TF_NUM_INPUTS); tf.setNumOutputs(TF_NUM_OUTPUTS); registerNetworkOps(tf); // macro generated by everywhereml while (!tf.begin(tfModel).isOk()) { Serial.println(tf.exception.toString()); delay(1000); } Serial.println("Model ready"); } void loop() { predictAndPrint("idle", idle, 0); predictAndPrint("horizontal", horizontal, 1); predictAndPrint("vertical", vertical, 2); Serial.print("Inference took: "); Serial.print(tf.benchmark.microseconds()); Serial.println(" us"); delay(1000); // Expected output: // Sample 'idle': expected=0, predicted=0 // Sample 'horizontal': expected=1, predicted=1 // Sample 'vertical': expected=2, predicted=2 // Inference took: 11480 us } ``` -------------------------------- ### Run TensorFlow Model for IRIS Dataset Prediction Source: https://github.com/eloquentarduino/eloquenttinyml/blob/main/README.md This example demonstrates how to load a TensorFlow Lite model (irisModel.h) and run predictions using the Eloquent TinyML library with tflm_esp32. Ensure the model header is included before the library and the correct runtime is selected for your board. The ARENA_SIZE should be adjusted through trial and error. ```cpp #include "irisModel.h" #include #include #define ARENA_SIZE 2000 Eloquent::TF::Sequential tf; void setup() { Serial.begin(115200); delay(3000); Serial.println("__TENSORFLOW IRIS__"); tf.setNumInputs(4); tf.setNumOutputs(3); tf.resolver.AddFullyConnected(); tf.resolver.AddSoftmax(); while (!tf.begin(irisModel).isOk()) Serial.println(tf.exception.toString()); } void loop() { if (!tf.predict(x0).isOk()) { Serial.println(tf.exception.toString()); return; } Serial.print("expcted class 0, predicted class "); Serial.println(tf.classification); if (!tf.predict(x1).isOk()) { Serial.println(tf.exception.toString()); return; } Serial.print("expcted class 1, predicted class "); Serial.println(tf.classification); if (!tf.predict(x2).isOk()) { Serial.println(tf.exception.toString()); return; } Serial.print("expcted class 2, predicted class "); Serial.println(tf.classification); Serial.print("It takes "); Serial.print(tf.benchmark.microseconds()); Serial.println("us for a single prediction"); delay(1000); } ``` -------------------------------- ### Get Predicted Class Index with tf.classification Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Access the `tf.classification` field, which holds the index of the highest-probability class after a `predict()` call. Defaults to 255 before the first successful prediction. ```cpp void loop() { float x[4] = { 5.9, 3.0, 5.1, 1.8 }; if (!tf.predict(x).isOk()) { Serial.println(tf.exception.toString()); return; } switch (tf.classification) { case 0: Serial.println("Iris setosa"); break; case 1: Serial.println("Iris versicolor"); break; case 2: Serial.println("Iris virginica"); break; default: Serial.println("Unknown"); break; } delay(1000); } ``` -------------------------------- ### Include Runtime Libraries for EloquentTinyML Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Include the appropriate runtime library for your board before using EloquentTinyML. Use `tflm_esp32.h` for ESP32 or `tflm_cortexm.h` for ARM Cortex-M boards. ```cpp #include // For ARM Cortex-M boards (e.g., Arduino Nano 33 BLE Sense) #include ``` -------------------------------- ### Load and Initialize TFLite Model with tf.begin() Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Use `tf.begin(modelData)` to load the FlatBuffer model. Check the return value with `.isOk()` to ensure successful initialization. Handle potential errors by printing `tf.exception.toString()`. ```cpp // Model header defines: myModel[], TF_NUM_OPS, TF_NUM_INPUTS, TF_NUM_OUTPUTS #include "myModel.h" #include #include #define ARENA_SIZE 5000 Eloquent::TF::Sequential tf; void setup() { Serial.begin(115200); delay(2000); tf.setNumInputs(TF_NUM_INPUTS); tf.setNumOutputs(TF_NUM_OUTPUTS); // Register ops — must match what the model actually uses tf.resolver.AddFullyConnected(); tf.resolver.AddRelu(); tf.resolver.AddSoftmax(); if (!tf.begin(myModel).isOk()) { // Possible errors: // "You must set the number of inputs" // "Model version mismatch. Expected X, got Y" // "AllocateTensors() failed" Serial.print("Init error: "); Serial.println(tf.exception.toString()); while (true); // halt } Serial.println("Model ready"); // Expected output: "Model ready" } ``` -------------------------------- ### Initialize Sequential Model with EloquentTinyML Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Initialize the `Eloquent::TF::Sequential` class with the number of operations and arena size. Include your model header before the library header. Tune `ARENA_SIZE` for your specific model. ```cpp #include "myModel.h" // include model BEFORE #include #include #define ARENA_SIZE 4000 // tune this for your model // TF_NUM_OPS is defined in myModel.h when generated by everywhereml Eloquent::TF::Sequential tf; void setup() { Serial.begin(115200); delay(3000); // Optional if myModel.h defines TF_NUM_INPUTS / TF_NUM_OUTPUTS tf.setNumInputs(4); tf.setNumOutputs(3); // Register only the ops your model uses tf.resolver.AddFullyConnected(); tf.resolver.AddSoftmax(); // Load model — retries until success while (!tf.begin(myModel).isOk()) Serial.println(tf.exception.toString()); Serial.println("Model loaded OK"); } ``` -------------------------------- ### tf.begin(modelData) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Loads the FlatBuffer model from a `const unsigned char[]` array, validates the schema version, allocates tensors in the arena, and returns a reference to the internal `Exception` object. Chain `.isOk()` to check success. ```APIDOC ## `tf.begin(modelData)` Loads the FlatBuffer model from a `const unsigned char[]` array, validates the schema version, allocates tensors in the arena, and returns a reference to the internal `Exception` object. Chain `.isOk()` to check success. ```cpp // Model header defines: myModel[], TF_NUM_OPS, TF_NUM_INPUTS, TF_NUM_OUTPUTS #include "myModel.h" #include #include #define ARENA_SIZE 5000 Eloquent::TF::Sequential tf; void setup() { Serial.begin(115200); delay(2000); tf.setNumInputs(TF_NUM_INPUTS); tf.setNumOutputs(TF_NUM_OUTPUTS); // Register ops — must match what the model actually uses tf.resolver.AddFullyConnected(); tf.resolver.AddRelu(); tf.resolver.AddSoftmax(); if (!tf.begin(myModel).isOk()) { // Possible errors: // "You must set the number of inputs" // "Model version mismatch. Expected X, got Y" // "AllocateTensors() failed" Serial.print("Init error: "); Serial.println(tf.exception.toString()); while (true); // halt } Serial.println("Model ready"); // Expected output: "Model ready" } ``` ``` -------------------------------- ### Using Pre-built Person Detection Model with ESP32 Camera Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Integrates the `personDetection` model from `eloquent_tinyml/zoo` with an ESP32 camera. Ensure the camera resolution is 96x96 and pixel format is grayscale. Evaluate the `personDetection` instance as a boolean to check for person detection. ```cpp #include #include #include #include using eloq::camera; using eloq::tinyml::zoo::personDetection; // Override default arena size if needed: // #define PERSON_DETECTION_ARENA_SIZE 90000L void setup() { Serial.begin(115200); delay(3000); camera.pinout.freenove_s3(); camera.brownout.disable(); camera.resolution.yolo(); // must be 96x96 camera.pixformat.gray(); // must be grayscale while (!camera.begin().isOk()) Serial.println(camera.exception.toString()); while (!personDetection.begin().isOk()) Serial.println(personDetection.exception.toString()); Serial.println("Ready. Point camera at a person."); } void loop() { if (!camera.capture().isOk()) { Serial.println(camera.exception.toString()); return; } if (!personDetection.run(camera).isOk()) { Serial.println(personDetection.exception.toString()); return; } if (personDetection) { Serial.print("Person detected! ("); Serial.print(personDetection.tf.benchmark.millis()); Serial.println(" ms)"); } else { Serial.println("No person."); } // Raw scores (0–255 range) Serial.print("Person score: "); Serial.println(personDetection.personScore()); Serial.print("Not-person score: "); Serial.println(personDetection.notPersonScore()); // Example output: // Person detected! (4230 ms) // Person score: 210 // Not-person score: 44 } ``` -------------------------------- ### Error Handling with Exceptions in Eloquent TinyML Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Demonstrates various patterns for handling exceptions returned by `begin()` and `predict()` methods. Use `.isOk()` to check for errors, `.toString()` for messages, and `operator bool()` for inline checks. Errors are sticky until cleared by a successful operation. ```cpp void setup() { Serial.begin(115200); delay(2000); tf.setNumInputs(4); tf.setNumOutputs(3); tf.resolver.AddFullyConnected(); tf.resolver.AddSoftmax(); // Pattern 1: while-loop retry while (!tf.begin(myModel).isOk()) Serial.println(tf.exception.toString()); // Pattern 2: halt on error if (!tf.begin(myModel).isOk()) { Serial.print("Fatal: "); Serial.println(tf.exception.toString()); while (true) delay(1000); } // Pattern 3: operator bool (true = has error) if (tf.exception) { Serial.println("Something went wrong!"); } // Pattern 4: severity check if (tf.exception.isSevere()) { Serial.println("Severe error, halting."); while (true); } } ``` -------------------------------- ### Run Int8 Quantized Inference with tf.predict() Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Use this overload for fully int8-quantized models. It directly copies the int8 input array and runs inference. Ensure your input data is already quantized. ```cpp void loop() { // Pre-quantized int8 input (e.g., from a camera sensor or pre-processing step) int8_t quantizedInput[96 * 96]; // ... fill quantizedInput from sensor ... if (!tf.predict(quantizedInput).isOk()) { Serial.print("Int8 predict error: "); Serial.println(tf.exception.toString()); return; } Serial.print("Classification: "); Serial.println(tf.classification); Serial.print("Inference: "); Serial.print(tf.benchmark.ms()); Serial.println(" ms"); } ``` -------------------------------- ### Eloquent::TF::Sequential Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt The core template class for running any TFLite model. It manages the full model lifecycle, including loading the FlatBuffer model, allocating the tensor arena, registering TFLite ops, and running predictions. ```APIDOC ## `Eloquent::TF::Sequential` `Sequential` is the main template class for running any TFLite model. The first template parameter `numOps` is the number of TFLite ops registered in the resolver; the second `arenaSize` (in bytes) is the tensor arena size — start high (e.g., 10000) and decrease until inference fails, then go back up by a small margin. ```cpp #include "myModel.h" // include model BEFORE #include #include #define ARENA_SIZE 4000 // tune this for your model // TF_NUM_OPS is defined in myModel.h when generated by everywhereml Eloquent::TF::Sequential tf; void setup() { Serial.begin(115200); delay(3000); // Optional if myModel.h defines TF_NUM_INPUTS / TF_NUM_OUTPUTS tf.setNumInputs(4); tf.setNumOutputs(3); // Register only the ops your model uses tf.resolver.AddFullyConnected(); tf.resolver.AddSoftmax(); // Load model — retries until success while (!tf.begin(myModel).isOk()) Serial.println(tf.exception.toString()); Serial.println("Model loaded OK"); } ``` ``` -------------------------------- ### Manually Configure Tensor Dimensions with setNumInputs/setNumOutputs Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Manually set the number of input and output values for the model using `tf.setNumInputs(n)` and `tf.setNumOutputs(n)` if your model header does not define `TF_NUM_INPUTS` or `TF_NUM_OUTPUTS`. ```cpp #include "customModel.h" // does NOT define TF_NUM_INPUTS / TF_NUM_OUTPUTS #include #include #define ARENA_SIZE 3000 Eloquent::TF::Sequential<4, ARENA_SIZE> tf; // 4 ops manually void setup() { Serial.begin(115200); tf.setNumInputs(6); // model expects 6 float features tf.setNumOutputs(2); // binary classification: 2 output scores tf.resolver.AddFullyConnected(); tf.resolver.AddRelu(); tf.resolver.AddSoftmax(); while (!tf.begin(customModel).isOk()) Serial.println(tf.exception.toString()); } ``` -------------------------------- ### Run Float32 Inference with tf.predict() Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Use this for float32 models. It copies input data, runs inference, and populates output scores and the classification index. Ensure the input array matches the model's expected format. ```cpp void loop() { // 4-feature sample for Iris classification float sample[4] = { 5.1, 3.5, 1.4, 0.2 }; if (!tf.predict(sample).isOk()) { Serial.print("Prediction error: "); Serial.println(tf.exception.toString()); return; } // tf.classification = index of highest-probability class Serial.print("Predicted class: "); Serial.println(tf.classification); // e.g. 0 // Access raw per-class probabilities Serial.print("Class 0 score: "); Serial.println(tf.output(0)); Serial.print("Class 1 score: "); Serial.println(tf.output(1)); Serial.print("Class 2 score: "); Serial.println(tf.output(2)); // Inference timing Serial.print("Inference took: "); Serial.print(tf.benchmark.microseconds()); Serial.println(" us"); delay(1000); // Example output: // Predicted class: 0 // Class 0 score: 0.97 // Class 1 score: 0.02 // Class 2 score: 0.01 // Inference took: 312 us } ``` -------------------------------- ### Quantize-then-Predict with tf.predictInt8() Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Use this when your model is int8-quantized but your input data is in float format. The library handles the quantization internally before running inference. ```cpp void loop() { float floatInput[10] = { 0.12, -0.34, 0.56, 0.78, -0.90, 0.11, 0.22, -0.33, 0.44, -0.55 }; if (!tf.predictInt8(floatInput).isOk()) { Serial.print("PredictInt8 error: "); Serial.println(tf.exception.toString()); return; } Serial.print("Class: "); Serial.println(tf.classification); delay(500); } ``` -------------------------------- ### Measure Inference Timing with Benchmark Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt The `tf.benchmark` object automatically measures inference latency. Use `.microseconds()`/`.us()` for high-resolution timing or `.millis()`/`.ms()` for millisecond precision. You can also time arbitrary code blocks. ```cpp void loop() { float x[4] = { 5.1, 3.5, 1.4, 0.2 }; if (!tf.predict(x).isOk()) return; Serial.print("Inference time: "); Serial.print(tf.benchmark.microseconds()); Serial.print(" us ("); Serial.print(tf.benchmark.millis()); Serial.println(" ms)"); // You can also benchmark any arbitrary code block: tf.benchmark.timeit([]() { // ... any code to time ... }); Serial.print("Custom block: "); Serial.print(tf.benchmark.us()); Serial.println(" us"); delay(1000); // Example output: // Inference time: 842 us (0 ms) } ``` -------------------------------- ### tf.predictInt8(float* x) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Quantize-then-Predict. Accepts float input, applies the model's input scale and zero-point quantization internally, then runs int8 inference. Useful when your model is int8-quantized but your data pipeline produces floats. ```APIDOC ## `tf.predictInt8(float* x)` — Quantize-then-Predict Accepts float input, applies the model's input scale and zero-point quantization internally, then runs int8 inference. Useful when your model is int8-quantized but your data pipeline produces floats. ```cpp void loop() { float floatInput[10] = { 0.12, -0.34, 0.56, 0.78, -0.90, 0.11, 0.22, -0.33, 0.44, -0.55 }; if (!tf.predictInt8(floatInput).isOk()) { Serial.print("PredictInt8 error: "); Serial.println(tf.exception.toString()); return; } Serial.print("Class: "); Serial.println(tf.classification); delay(500); } ``` ``` -------------------------------- ### Benchmark Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Inference Timing. The tf.benchmark object automatically measures inference latency during each predict() call. Use .microseconds() / .us() for high-resolution timing or .millis() / .ms() for millisecond precision. ```APIDOC ## `Benchmark` — Inference Timing The `tf.benchmark` object (of type `Eloquent::Extra::Time::Benchmark`) automatically measures inference latency during each `predict()` call. Use `.microseconds()` / `.us()` for high-resolution timing or `.millis()` / `.ms()` for millisecond precision. ```cpp void loop() { float x[4] = { 5.1, 3.5, 1.4, 0.2 }; if (!tf.predict(x).isOk()) return; Serial.print("Inference time: "); Serial.print(tf.benchmark.microseconds()); Serial.print(" us ("); Serial.print(tf.benchmark.millis()); Serial.println(" ms)"); // You can also benchmark any arbitrary code block: tf.benchmark.timeit([]() { // ... any code to time ... }); Serial.print("Custom block: "); Serial.print(tf.benchmark.us()); Serial.println(" us"); delay(1000); // Example output: // Inference time: 842 us (0 ms) } ``` ``` -------------------------------- ### tf.setNumInputs(n) / tf.setNumOutputs(n) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Sets the expected number of input and output values for the model. These are automatically read from `TF_NUM_INPUTS` / `TF_NUM_OUTPUTS` macros if the model header was generated by the `everywhereml` Python package; call these manually otherwise. ```APIDOC ## `tf.setNumInputs(n)` / `tf.setNumOutputs(n)` Sets the expected number of input and output values for the model. These are automatically read from `TF_NUM_INPUTS` / `TF_NUM_OUTPUTS` macros if the model header was generated by the `everywhereml` Python package; call these manually otherwise. ```cpp #include "customModel.h" // does NOT define TF_NUM_INPUTS / TF_NUM_OUTPUTS #include #include #define ARENA_SIZE 3000 Eloquent::TF::Sequential<4, ARENA_SIZE> tf; // 4 ops manually void setup() { Serial.begin(115200); tf.setNumInputs(6); // model expects 6 float features tf.setNumOutputs(2); // binary classification: 2 output scores tf.resolver.AddFullyConnected(); tf.resolver.AddRelu(); tf.resolver.AddSoftmax(); while (!tf.begin(customModel).isOk()) Serial.println(tf.exception.toString()); } ``` ``` -------------------------------- ### tf.predict(float* x) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Runs Float32 inference. Copies the input float array into the input tensor, invokes the interpreter, reads output scores, sets the classification, and updates the benchmark timer. Returns the Exception reference. ```APIDOC ## `tf.predict(float* x)` — Run Float32 Inference Copies the input float array into the input tensor, invokes the interpreter, reads output scores into `tf.outputs[]`, sets `tf.classification` (argmax), and updates the benchmark timer. Returns the `Exception` reference. ```cpp void loop() { // 4-feature sample for Iris classification float sample[4] = { 5.1, 3.5, 1.4, 0.2 }; if (!tf.predict(sample).isOk()) { Serial.print("Prediction error: "); Serial.println(tf.exception.toString()); return; } // tf.classification = index of highest-probability class Serial.print("Predicted class: "); Serial.println(tf.classification); // e.g. 0 // Access raw per-class probabilities Serial.print("Class 0 score: "); Serial.println(tf.output(0)); Serial.print("Class 1 score: "); Serial.println(tf.output(1)); Serial.print("Class 2 score: "); Serial.println(tf.output(2)); // Inference timing Serial.print("Inference took: "); Serial.print(tf.benchmark.microseconds()); Serial.println(" us"); delay(1000); // Example output: // Predicted class: 0 // Class 0 score: 0.97 // Class 1 score: 0.02 // Class 2 score: 0.01 // Inference took: 312 us } ``` ``` -------------------------------- ### tf.predict(int8_t* x) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Runs Int8 Quantized inference. Copies a raw `int8_t` array directly into the input tensor, invokes inference, and reads raw `int8_t` output values. ```APIDOC ## `tf.predict(int8_t* x)` — Run Int8 Quantized Inference Overload for fully int8-quantized models. Copies a raw `int8_t` array directly into the input tensor (no scale/offset applied by the library), invokes inference, and reads raw `int8_t` output values into `tf.outputs[]`. ```cpp void loop() { // Pre-quantized int8 input (e.g., from a camera sensor or pre-processing step) int8_t quantizedInput[96 * 96]; // ... fill quantizedInput from sensor ... if (!tf.predict(quantizedInput).isOk()) { Serial.print("Int8 predict error: "); Serial.println(tf.exception.toString()); return; } Serial.print("Classification: "); Serial.println(tf.classification); Serial.print("Inference: "); Serial.print(tf.benchmark.ms()); Serial.println(" ms"); } ``` ``` -------------------------------- ### Access Individual Output Score with tf.output(i) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Retrieve the raw output score for a specific class or output index. Returns NaN if outputs are not populated or the index is out of bounds. Useful for regression or custom multi-output models. ```cpp void loop() { float x[4] = { 6.3, 3.3, 6.0, 2.5 }; if (!tf.predict(x).isOk()) return; // For regression or custom multi-output models, read outputs individually for (int i = 0; i < 3; i++) { Serial.print("Output["); Serial.print(i); Serial.print("] = "); Serial.println(tf.output(i)); } // Output[0] = 0.01 // Output[1] = 0.03 // Output[2] = 0.96 ← highest → classification = 2 } ``` -------------------------------- ### tf.output(i) Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Access Individual Output Score. Returns the i-th raw output value as a float. Returns NaN if outputs have not been populated or i is out of bounds. ```APIDOC ## `tf.output(i)` — Access Individual Output Score Returns the `i`-th raw output value as a float. Returns `NaN` (via `sqrt(-1)`) if outputs have not been populated or `i` is out of bounds. ```cpp void loop() { float x[4] = { 6.3, 3.3, 6.0, 2.5 }; if (!tf.predict(x).isOk()) return; // For regression or custom multi-output models, read outputs individually for (int i = 0; i < 3; i++) { Serial.print("Output["); Serial.print(i); Serial.print("] = "); Serial.println(tf.output(i)); } // Output[0] = 0.01 // Output[1] = 0.03 // Output[2] = 0.96 ← highest → classification = 2 } ``` ``` -------------------------------- ### Registering TFLite Operations for Custom Models Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Manually register TFLite operations required by your model using `tf.resolver.Add()` methods. This is necessary for models not generated by `everywhereml` which handles auto-registration. Missing operations will cause errors during tensor allocation or invocation. ```cpp // Manually register ops for a CNN model tf.resolver.AddConv2D(); tf.resolver.AddDepthwiseConv2D(); tf.resolver.AddAveragePool2D(); tf.resolver.AddReshape(); tf.resolver.AddSoftmax(); ``` ```cpp // Manually register ops for a dense network tf.resolver.AddFullyConnected(); tf.resolver.AddRelu(); tf.resolver.AddSoftmax(); ``` ```cpp // Manually register ops for an LSTM model tf.resolver.AddFullyConnected(); tf.resolver.AddSoftmax(); // (plus any ops used by the LSTM cell itself) ``` ```cpp // Available op registration methods: // tf.resolver.AddAdd() // tf.resolver.AddAveragePool2D() // tf.resolver.AddConcatenation() // tf.resolver.AddConv2D() // tf.resolver.AddDepthwiseConv2D() // tf.resolver.AddElu() // tf.resolver.AddFullyConnected() // tf.resolver.AddLeakyRelu() // tf.resolver.AddMaxPool2D() // tf.resolver.AddMaximum() // tf.resolver.AddMinimum() // tf.resolver.AddRelu() // tf.resolver.AddReshape() // tf.resolver.AddSoftmax() ``` -------------------------------- ### tf.classification Source: https://context7.com/eloquentarduino/eloquenttinyml/llms.txt Predicted Class Index. A uint8_t field automatically set to the argmax of tf.outputs[] after each predict() call when numOutputs >= 2. Defaults to 255 before the first successful prediction. ```APIDOC ## `tf.classification` — Predicted Class Index A `uint8_t` field automatically set to the argmax of `tf.outputs[]` after each `predict()` call when `numOutputs >= 2`. Defaults to `255` before the first successful prediction. ```cpp void loop() { float x[4] = { 5.9, 3.0, 5.1, 1.8 }; if (!tf.predict(x).isOk()) { Serial.println(tf.exception.toString()); return; } switch (tf.classification) { case 0: Serial.println("Iris setosa"); break; case 1: Serial.println("Iris versicolor"); break; case 2: Serial.println("Iris virginica"); break; default: Serial.println("Unknown"); break; } delay(1000); } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.