TinyML Occupancy Classification Example with Consentium IoT

This example demonstrates how to use Consentium IoT's TinyML and EdgeNeuron AI platforms to perform real-time occupancy classification using the AMG8833 Grid-EYE thermal sensor and TensorFlow Lite Micro. The project is designed for edge devices like the ESP32 and Raspberry Pi Pico W.


Features

  • Edge Compatibility: Works seamlessly with ESP32 and Raspberry Pi Pico W.

  • Real-time Inference: Employs TensorFlow Lite Micro for low-latency predictions.

  • Occupancy Classification: Identifies room occupancy in the following categories:

    • Empty

    • One Person

    • Two Persons

    • Three Persons


Prerequisites

Hardware Requirements

  1. Edge Board: ESP32 or Raspberry Pi Pico W

  2. Sensor: AMG8833 Grid-EYE Thermal Sensor

  3. Connections: I2C communication setup (SCL and SDA)

Software Requirements

  • Arduino IDE with relevant libraries:

    • EdgeNeuron.h

    • EdgeMath.h

    • SparkFun_GridEYE_Arduino_Library.h


Code Overview

1. Header Section

The header provides essential information about the example, including its purpose, supported features, and licensing.

2. Libraries and Configuration

  • Wire.h: For I2C communication.

  • EdgeNeuron.h: Facilitates model initialization and inference.

  • EdgeMath.h: Handles preprocessing like scaling and finding maximum probabilities.

  • SparkFun_GridEYE_Arduino_Library.h: Provides an interface for the AMG8833 sensor.


3. Memory Allocation for TensorFlow Lite Model

  • Tensor Arena: Allocates memory for model inference.

  • Input and Output Tensors:

    • kInputSize: 64 (8x8 thermal sensor pixels).

    • kOutputSize: 4 (class probabilities).


4. Class Labels

Defines human-readable labels for the predicted classes.


5. Setup Function

Tasks Performed:

  1. Initializes the serial monitor for debugging.

  2. Configures the Grid-EYE sensor for data capture.

  3. Initializes the TensorFlow Lite Micro model using the EdgeNeuron platform.


6. Loop Function

Main Steps:

  1. Capture Data from Grid-EYE Sensor

    • Captures the 8x8 thermal grid data from the sensor.

    • Replaces invalid data points (NaN) with 0.0.


  1. Preprocess Input Data

    • Scales the input data using mean and scale values from training.


  1. Set Model Input Tensor

    • Loads the preprocessed data into the model's input tensor.


  1. Run Model Inference

    • Executes the TensorFlow Lite model for real-time inference.


  1. Retrieve Output and Predict Class

    • Retrieves the predicted probabilities for each class.

    • Uses argmax to identify the class with the highest probability.


  1. Log Class Probabilities

    • Outputs the predicted class probabilities to the serial monitor.


7. Delay for the Next Cycle

Introduces a 1-second delay between consecutive inferences.


Example Output

Serial Monitor Logs


References


License

This project is licensed under the MIT License. Redistribution must include the header file.

Last updated

Was this helpful?