Control your TV, Air Conditioner or Lightbulb by just pointing your finger at them, using the BrainChip AKD1000 achieving great accuracy and low power consumption.
Created By: Christopher Mendez
Public Project Link: https://studio.edgeimpulse.com/public/319871/latest
Today more than ever we live with smart devices and personal assistants that work together to make our environment a more comfortable, efficient and personalized place. This project aims to contribute to the same field by suggesting a radical change in how we interact with smart things.
Sometimes it can be inconvenient to have to ask a personal assistant to turn our appliances on or off. Because it's simply too late at night to be talking, or because we're watching our favorite movie and we don't want annoying audio interrupting us.
This is why I thought "What if we could control the whole house with just gestures?" It would be amazing to just point to the air conditioner and turn it on, turn off the light, and turn on our TV.
To develop this project we will use a BrainChip Akida Development Kit and a Logitech BRIO 4K Webcam, together with an Edge Impulse Machine Learning model for pose identification.
It should be noted that this kit is the main component of this project thanks to some interesting characteristics that make it ideal for this use case. This kit consists of a Raspberry Pi Compute Module 4 with Wi-Fi and 8 GB RAM, also its IO Board, which includes a PCIe interface to carry an Akida PCIe board with the AKD1000 Neuromorphic Hardware Accelerator.
Considering that our project will end up being one more smart device that we will have at home, it's crucial that it can do its job efficiently and with very low energy consumption. This is where BrainChip's technology makes sense. Akida™ neuromorphic processor mimics the human brain to analyze only essential sensor inputs at the point of acquisition—processing data with unparalleled performance, precision, and economy of energy.
The whole system will be running independently identifying poses, if a desired pose is detected it will send an HTTP request to the Google Assistant SDK being hosted by a Raspberry Pi with Home Assistant OS.
The system comes with the basic requirements installed to run machine learning models using Akida processor acceleration. Once the system is powered up and connected to the internet (I used an ethernet cable), you can access it by an SSH connection: you will need to know the device's local IP address, in my case, I got it from the list of connected devices of my router.
To verify the device is working properly, you can try an included demo by navigating to http://<your_kit_IP>, in my case to http://10.0.0.150 and try some of the examples:
To start setting up the device for a custom model deployment, let's verify we have installed all the packages we need.
I am using Putty for the SSH connection. Log in using the Administrator credentials, in this case, the username is ubuntu and the password is brainchip.
Once inside you will be able to install some required dependencies:
Running the built-in demos ensures us that the system already recognizes the Akida package and the PCIe drivers for the AKD1000, but we can verify it by running the following commands:
You will also need Node Js v14.x to be able to use the Edge Impulse CLI. Install it by running these commands:
The last command should return the node version, v14 or above.
Finally, let's install the Linux Python SDK, you just need to run these commands:
As we are working with computer vision, we will need "opencv-python>=4.5.1.48, "PyAudio", "Psutil", and "Flask"
First, we need to create an Edge Impulse Studio account if we haven't yet, and create a new project:
For the creation of the dataset of our model, we have two options, uploading the images from the BrainChip Development Kit or using our computer or phone. In this case, I chose to take them from the computer using the same webcam that we are finally going to use in the project.
The dataset consists of 3 classes in which we finger point each appliance and a last one of unknown cases.
Taking at least +50 pictures of each class will let you create a robust enough model
After having the dataset ready, it is time to define the structure of the model.
In the left side menu, we navigate to Impulse design > Create impulse and define the following settings for each block, respectively:
Image width: 192
Image height: 192
Resize mode: Fit longest
Use this block to turn raw images into pose vectors, then pair it with an ML block to detect what a person is doing.
PoseNet processing block is just enabled for Enterprise projects, if we want to use it on a Developer one, we need to locally run the block, for this, you must clone the PoseNet block repository and follow the README steps.
You will end up with an URL similar to "https://abe7-2001-1308-a2ca-4f00-e65f-1ff-fe27-d3aa.ngrok-free.app" hosting the processing block, click on Add a processing block > Add custom block, then paste the ngrok generated URL, and click on Add block.
To classify the features extracted from the different poses, we'll use a classification learn block specifically designed for the hardware we're using.
Finally, we save the Impulse design, it should end up looking like this:
After having designed the impulse, it's time to set the processing and learning blocks. The Pose estimation block doesn't have any configurable parameters, so we just need to click on Save parameters and then Generate features.
In the classifier block define the following settings:
Number of training cycles: 100
Learning rate: 0.001
In the Neural network architecture, add 3 Dense layers with 35, 25 and 10 neurons respectively.
Here is the architecture "Expert mode" code (you can copy and paste it from here):
Click on the Start training button and wait for the model to be trained and the confusion matrix to show up.
The results of the confusion matrix can be improved by adding more samples to the dataset.
To be able to run the project, we need to go back to our SSH connection with the device and clone the project from the Github repository, for this, use the following command:
Install all the project requirements with the following command, and wait for the process to be done.
Install these other required packages with:
Once the project is cloned locally in the Akida Development Kit, you can download the project model from Edge Impulse Studio by navigating to the Dashboard section and downloading the MetaTF .fbz
file.
Once downloaded, from the model path, open a new terminal and copy the model to the Dev Kit using scp
command as follows:
You will be asked for your Linux machine login password.
Now, the model is on the Akida Dev Kit local storage (/home/ubuntu)
and you can verify it by listing the directory content using ls
.
Move the model to the project directory with the following command:
Here we have the model on the project directory, so now everything is ready to be run.
To run the project, type the following command:
The first parameter class-pose.py
is the project's main script to be run.
akida_model.fbz
is the Meta TF model name we downloaded from our Edge Impulse project.
0
force the script to use the first camera available.
The project will start running and printing the inference results continuously in the terminal.
To watch a preview of the camera feed, you can do it by opening a new ssh
session and running the make-page.py
script from the project directory:
Finally, you will be able to see the camera preview alongside the inference results organized in the following order: AC
, Light
, Other
and TV
.
For the actual appliance control, I used the Google Assistant SDK integration for Home Assistant. Follow the documentation to configure it for your setup.
The Home Assistant is running on a separate Raspberry PI.
Once the integration is set, we can send HTTP
requests to it with the following format:
URL: http://<Raspberry Pi IP>:8123/api/services/google_assistant_sdk/send_text_command
Headers:
Authorization: "Bearer "
Content-Type: "application/json"
Body: {"command":"turn on the light"}
You must edit the url
and auth
variables in the code with the respective ones of your setup.
Here I show you the whole project working and controlling appliances when they are pointed.
This project leverages the Brainchip Akida Neuromorphic Hardware Accelerator to propose an innovative solution to home automation. It can be optimized to work as a daily used gadget that may be at everyone's house in the near future.