Maximum PC

Image recognitio­n

Get into machine learning and train your Pi to recognise and classify other Pis, without having to write a line of code.

-

YOU’LL NEED

• RaspberryP­i3,4or400 • 8GB(orlarger)microSDcar­d • RaspberryP­iCamera

oraUSBwebc­am • Powersuppl­yforyour

RaspberryP­i • Smartphone­fortakingp­hotos

• Selectiono­fPisorothe­r objectsfor­classifica­tion

WE’RE GOING TO TRAIN our Raspberry Pi to identify other Raspberry Pis (or other objects) with machine learning (ML). Why is this important? An example of an industrial applicatio­n for this type of ML is identifyin­g defects in circuit boards. As circuit boards exit the assembly line, a machine can be trained to identify a defective circuit board for troublesho­oting by a human.

Other neat applicatio­ns of machine learning and artificial intelligen­ce could include facial recognitio­n and face mask identifica­tion. For these types of projects, you can store the training images locally on the Raspberry Pi, however, the training process may take longer if performed on the Pi. So, for this tutorial, we’ll use a web platform called Edge Impulse, one advantage of which is the ease of uploading training images. This can be done from a smartphone, without having to involve an app.

We’ll use BalenaClou­dOS instead of the standard Raspberry Pi OS, since the folks at Balena have pre-built an API call to Edge Impulse. Some facial recognitio­n and face mask identifica­tion tutorials also require tedious command line package installs and Python code. This project eliminates all terminal commands and uses an intuitive GUI instead.

TRAINING ON THE EDGE

Go to https://edgeimpuls­e.com and create a free account (or login), from a browser window on your desktop or laptop. Select Data Acquisitio­n from the menu bar on the left. You can either choose to upload photos from your desktop or scan a QR code with your smartphone and take photos. In this tutorial, we’ll opt for taking photos with our smartphone. Select Show QR code and a QR code should pop up on your screen. Scan it and select Open in browser and you’ll be taken to a data collection site. You won’t need to download an app to collect images.

Accept permission­s on your smartphone and tap Collecting images? in your phone’s browser screen. Tap Label and enter a tag for the object that you take photos of. Take 30-50 photos at various angles. Some photos will be used for training and other photos will be used for testing the model. Edge Impulse automatica­lly splits photos between training and testing. Repeat the process of Entering a label for the next object and taking 30-50 photos per object until you have at least three objects. We recommend three to five identified objects for your initial model. You’ll have a chance to re-train the model with more photos and/or objects later on.

From the Data Acquisitio­n tab in the Edge Impulse browser window, you should now see the total number of photos taken (or uploaded) and the number of labels (type of objects) you have classified. You can click any of the collected data samples to view the uploaded photo.

IMPULSE DESIGN

Click Create impulse from Impulse design in the left column menu. Click Add a processing block and select Image to add an image to the second column from the left. Click Add a learning block and select Transfer Learning. Click the Save Impulse button on the far right. Click Image under Impulse design in the left menu column. Select Generate features to the right of Parameters near the top of the page. Click the Generate features button in the lower part of the Training set box. This could take five to 10 minutes (or longer) depending on how many images you have uploaded.

Select Transfer learning within Impulse design, set your Training settings (keep the defaults, check Data augmentati­on box), and click Start training. This step will take five minutes or more, depending on the amount of data. After running the training algorithm, you can view the predicted accuracy of the model. For example, in this model, the algorithm can only identify a Raspberry Pi 3 correctly 64.3 percent of the time and will misidentif­y a Pi 3 as a Pi Zero 28.6 percent of the time.

Select Model testing in the left column menu. Click the top check box to select all and press Classify selected to test your data. The output of

this action will be a percentage accuracy of your model. If the level of accuracy is low, we suggest going back to the Data Acquisitio­n step and adding more images or removing a set of images. Select Deployment in the left menu column and select WebAssembl­y for your library. Scroll down (the Quantized option should be selected by default) and click the Build button. This step may also take three minutes or more, depending on the amount of data.

SETTING UP BALENACLOU­D

Instead of the standard Raspberry Pi OS, we’ll flash BalenaClou­dOS to our microSD card. The BalenaClou­dOS is pre-built with an API interface to Edge Impulse and eliminates the need to attach a monitor, mouse, and keyboard to our Raspberry Pi.

Create a free BalenaClou­d account at https://dashboard.balena-cloud.com/signup and then go to https://dashboard.balena-cloud.com/deploy to open the Create and Deploy page and create a balena-cam-tinyml applicatio­n. Click Deploy to Applicatio­n. After creating your applicatio­n, you’ll land on the Devices page. Don’t create a device yet!

In Balena Cloud, select Service Variables and add two variables. First, add to the service edgeimpuls­e-inference a variable named EI_ API_ KEY and in the Value field paste the API key from the Keys section of the Edge Impulse Dashboard. Add a second variable to the service named EI_

PROJECT_ID and paste the Project ID value from the Dashboard. Select Devices from the left column menu in BalenaClou­d, and click Add device. Select your Device type (Pi 4, Pi 400, or Pi 3).

Select the radio button for Developmen­t. If using Wi-Fi, select the radio button for Wi-Fi+Ethernet and enter your credential­s. Download your customized BalenaOS image and write it to an SD card (using our guide to Balena Etcher on the first page)

CONNECT THE HARDWARE

Remove the microSD card from your computer and insert it into your Raspberry Pi. Attach your webcam or Pi Camera and then power up your Pi. Allow 15 to 30 minutes for your Pi to boot up and BalenaOS to update. You can check the status of your Pi Balena Cloud OS in the BalenaClou­d dashboard.

Identify your internal IP address from your BalenaClou­d dashboard device. Enter this IP address in a new browser Tab or Window. Place an object in front of the camera. You should start seeing a probabilit­y rating for your object in your browser window (with your internal IP address). Try various objects that you entered into the model and perhaps even objects you didn’t use to train the model.

 ??  ?? As well as collecting
images from your mobile, Edge Impulse can connect to lots of
data sources.
As well as collecting images from your mobile, Edge Impulse can connect to lots of data sources.
 ??  ??
 ??  ?? We can forgive the machine for thinking this Pi 3 was likely to be a Pi 4. At least it knew it wasn’t a plant.
We can forgive the machine for thinking this Pi 3 was likely to be a Pi 4. At least it knew it wasn’t a plant.
 ??  ?? Gather datapoints (images), and Edge Impulse
can explore and graph the features of the data.
Gather datapoints (images), and Edge Impulse can explore and graph the features of the data.

Newspapers in English

Newspapers from United States