In this follow on from my last PowerWire article on ActiveMQ, we will be using a Raspberry Pi, with Machine Learning, to take photos of birds feeding in our garden.
This part of the series will focus on the ML segment to take a photograph and let machine learning decide what is in it. After that, in my next article, we will send the information over to the IBM i for notification purposes.
For ease, and time constraints, we will be using Node-RED to take a picture, then pass that image through to a Machine Learning module to interrogate the photo and decide if there are any birds in there and not the squirrels after their share of the nuts!
Node-RED, which also runs on many platforms, including the IBM i, is very easy to use for this type of project. Further details on Node-RED can be found at https://nodered.org/
Preparing the Raspberry Pi
Node-RED is pre-installed on our Raspberry Pi, so no installation procedures necessary.
We must ensure the Raspberry Pi server is up and running. To achieve this, run the following command in a terminal window on the Raspberry Pi.
If running successfully, you should see the figure below.
Top Tip: Keep an eye on the server log, it is there to help you.
Once the server is running, we can point a browser, from any device anywhere on our network, to the Node-RED interface on the Raspberry Pi. By default, it runs on port 1880.
For the machine learning part of this project, I will be using the TensorFlow model, which has a Node-RED interface for us to use.
It was originally developed by Google.
Given any image, the model is capable of detecting 80 types of object, such as cat, tennis racket, bird, banana amongst many others. All very impressive.
For full details about the TensorFlow object detection, visit their web-site here.
The following node packages need to be added to our application. All other nodes are part of the base package and do not need to be explicitly added.
- node-red-contrib-camerapi to access our camera
- node-red-contrib-image-output to show the images captured
- node-red-contrib-tensorflow for the Machine Learning part
- node-red-contrib-loop to provide the loop function
- node-red-contrib-fs-ops to prove the file delete function
Use the Manage Pallette feature to add the above packages.
This can be seen in the figure below.
Once we have these all installed, we can put all the pieces together.
In this first example, I’ll get the Raspberry Pi to perform some of the basic stages. Here I will get the Raspberry Pi to take any photo and pass it through the Machine Learning module to see what it thinks is in the photo. Me with a chair seems a starting point!
Drag the nodes as listed in the figure below.
In this next part we will get the Raspberry Pi to take a snapshot of 10 photos, pass them through the Machine Learning module.
Then if the photo does not contain a bird, do some housekeeping by deleting the image.
It will do nothing if it does contain a bird. This is where we will send details to the IBM i, this will be in the next article.
It can take a time for the TensorFlow node to process the photo that has been taken.
This can be improved by following their recommendations on Node-RED start up. Which is;
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require(‘@tensorflow/tfjs-node’); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
That has accessed our Raspberry Pi, we now have it all configured and ready to send data to our IBM i. In the next article, I’ll piece it all together and send the information found to our IBM i.
All the examples I have written for this article, and previous ones, can be found on my open-source repository on GitHub, which can be found at https://github.com/formaserve/f_Learning
If you have any questions, either on this article, or anything else on the IBM i, use the comments below, or send me a message on twitter @AndyYouens
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.