Computer vision executes various techniques and approaches to identify objects in digital images, such as R-CNN, Fast R-CNN, Faster R-CNN, and YOLO, among others. The process of object recognition is quite complex and consists of a range of related tasks, including image classification, object localization, and object detection.
For better understanding, I attach the example of image recognition using a Region-based Convolutional Neural Network (R-CNN):
However, such technologies are quite demanding in use due to the following factors:
- High time and energy consumption
- Complex scaling of computer vision systems
- Use of complex deep learning algorithms that require the participation of data scientists
- Need for a large amount of equipment such as surveillance video cameras
- High costs for equipment and human resources
Since I believe that technologies should be easy to implement and available to more users, I’d like to offer a no less effective way to detect room occupancy, which will help to overcome the challenges mentioned above.
Sensor Data + TinyML Algorithms
In this tutorial, I’ll demonstrate how to efficiently use tabular data and automatically build a tiny machine learning model based on environmental sensor data to detect room occupancy.
But before describing the process in detail, I want to share the main advantages of my method:
- The resulting model is incomparably more compact than any computer vision model. And consequently, technologies and HW for the model operation will be cheaper and consume less energy and memory.
- It’s budget-friendly since I use a free platform and sensors cost less than cameras.
- It requires minor time and energy consumption.
Now let me proceed with the step-by-step procedure of the TinyML model creation.
This is a binary classification task as we need to predict whether a room is occupied or not, based on data from environmental sensors, such as temperature, humidity, light, and CO2.
For my experiment, I used an open-source “Occupancy Detection” dataset available on the UCI Machine Learning Repository: https://archive.ics.uci.edu/ml/datasets/Occupancy+Detection+
For model training, I use a free no-code platform, Neuton TinyML. Here are the steps of the process:
- I created a new solution and uploaded a training dataset that I downloaded from the UCI Machine Learning repository.
- Then I selected a target variable “Target” and the target metric “Accuracy”.
- To make a truly compact model that would fit into the tiniest sensor, I enabled the TinyML mode and selected 8-bit depth.
That’s all I needed to start model training :)
The trained model turned out to be super small and accurate, according to all the canons of TinyML. Looking ahead, I also provide Total footprint and RAM usage in the table :)
Just note the small number of coefficients (only 60!). And, most importantly, the model’s accuracy (which is 98%) is not affected by the small size which is fantastic!
For the purity of the experiment, I wanted to compare the metrics of Neuton’s model with the model built with one of the most used platforms, TensorFlow Lite for microcontrollers. But unlike Neuton, TF Lite for Microcontrollers requires a 32-bit platform, and therefore it would not be possible to deploy it to Arduino Mega 2560 which has an 8-bit MCU (ATmega2560).
For model deployment, generate the C library on the Neuton platform by clicking on the “Download” button. The contents of the library include the model, a set of functions used to perform preprocessing operations, and a set of functions used by the application logic to execute the model and read prediction results.
The code is available here: https://github.com/Neuton-tinyML/arduino-room-occupancy
To integrate the library, take the following steps:
- Include the library
- Declare input variable and set input values
- Run predictions
Since I use...Read more »