Sign in Start for free
Blog
05-16-2022

Tabular Data VS Computer Vision: Detecting Room Occupancy


 

Introduction

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 we say that there’s a more budget-friendly way to detect occupancy than real-time video analysis? In this tutorial, we 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.


Vision-based Method

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, we 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 we believe that technologies should be easy to implement and available to more users, we’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, we’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, we 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.


Model Training

Now let us 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 this experiment, we 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, we use a free no-code platform, Neuton TinyML. Here are the steps of the process:

  1. We created a new solution and uploaded a training dataset that we downloaded from the UCI Machine Learning repository.

  2. Then we selected a target variable “Target” and the target metric “Accuracy”.

  3. To make a truly compact model that would fit into the tiniest sensor, we enabled the TinyML mode and selected 8-bit depth.

  4. That’s all we 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, we 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, we 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).

 

Model Deployment

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 we use CSV data as input, we 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, we 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.

 

Final Words

We hope that our 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!


Stay updated, join our community