Tabular Data Vs Computer Vision: Detecting Room Occupancy
About the project
Learn why room occupancy detection using environmental sensors and tabular data wins over computer vision.
Estimated time: 1 hour
Items used in this project
Today, room occupancy detection is widely used in public places as a way to provide safety, manage energy consumption, etc. Most people tend to think that occupancy detection based on computer vision is the most common way to monitor presence in specific rooms and areas.
But what if I say that there’s a more budget-friendly way to detect occupancy than real-time video analysis? In my tutorial, I want to show an alternative way to detect people in the room, which is easier and cheaper to implement and doesn’t require any special data science knowledge.
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 CSV data as input, I will send 4 different conditions (which are described by values of features) of the room to detect its occupancy.
To emulate the work of a model, I connected a microcontroller to a computer via a serial port, and the communication took place in a binary format.
A sound signal on the video notifies that there is a person in the room.
I hope that my tutorial proved that you don’t need to be a computer vision genius to implement real-world projects. Now you know an alternative way to detect room occupancy by leveraging the power of TinyML, which doesn’t require high costs or efforts, just a free no-code platform!