Blog post

We’re Counting on You, FOMO!

Projects
By Nick Bild
We’re Counting on You, FOMO!

Counting may be so easy that a child can do it, but machines have a great way of making it look like a Herculean feat. Mechanical counters must be designed specifically for the type of items that they are to count, and tend to be very complicated and expensive. A great deal of precision must go into the design to allow for the separation and manipulation of items to get an accurate tally. This can lead to slowdowns in industrial settings where counting machines introduce a rate-limiting bottleneck and, on occasion, halt processes entirely due to maintenance issues.

In part due to the aforementioned issues, and also because some items are simply too difficult to count mechanically, weight is sometimes used as a proxy for a count. But weight may not be accurate enough for all use cases. This method makes the assumption that each object has the exact same weight, which does not always hold true — consider materials like wood and rubber where density can change by up to 50% depending on various environmental conditions. One very promising technology that may be able to overcome these problems and help to develop an inexpensive, simple, accurate, and fast counter is computer vision. When paired with an appropriate hardware platform and machine learning algorithm developed with Edge Impulse, engineer Nekhil Ravi has shown that this goal is achievable, and the best part is that the same device can easily be adapted to count any number of varied item types.

The Raspberry Pi-based device

Ravi selected a Raspberry Pi 4 single-board computer to power the design because the 1.5 GHz 64 bit quad-core Arm Cortex-A72 processor makes it a very powerful edge computing device, yet they retail for as little as $35 in single unit quantities. A five-megapixel Raspberry Pi Camera Module was also included to give the device the ability to capture images. This tiny but powerful hardware platform can be mounted anywhere it has a clear view of the objects to be counted, and does not require any other changes to the existing processes.

After sorting out the hardware, Ravi turned his attention to developing a machine learning data analysis pipeline with Edge Impulse Studio. The ground-breaking FOMO algorithm that was released earlier this year runs 30 times faster than MobileNet-SSD in object detection and counting tasks, and is optimized to run on resource-constrained edge devices, so it looked to be the perfect tool for the job. An impulse was created to preprocess image data and feed it into a FOMO model.

Labeling the training images for FOMO

To test out the idea, Ravi collected a dataset consisting of images of washers, faulty washers, bolts, and lollipops. These images were uploaded to Edge Impulse, then labeled using the labeling queue tool. Labels were assigned by dragging bounding boxes around each object within the web interface — but since this tool uses a YOLOv5 model to estimate the bounding box locations, it will do most of the work for you. Simply verify that the boxes look correct, and click to move to the next example.

Using a fairly small image dataset, the training process was kicked off. This was followed up by running the model testing tool, which uses a set of images that were held out from the training process to validate the accuracy of the model. Accuracy was observed to have reached 87.5% on the first try, which is quite good when working with a small dataset. Collecting some more example images to train the model with would be expected to improve the accuracy further.

Checking the accuracy of the model

Since everything checked out, the model was deployed to the Raspberry Pi via the Edge Impulse deployment tool. This enables the device to operate without transmitting data to the cloud for processing. Ravi wanted to make the data available for users in an easy-to-consume manner, so he set up a remote database that results from the model inferences are loaded into. That database powers a web application that shows real-time counts of various items that have been detected by the device.

What was that? You say that this project sounds great and all, but you have no need for counting washers and lollipops? Keep in mind that you can use this same method to count virtually anything — just clone Ravi’s public Edge Impulse project, then supply your own dataset of the items that you are interested in counting. And if a Raspberry Pi does not work for you either, then Edge Impulse can deploy the same model to dozens of other hardware platforms with just a few clicks. Take a look at the project documentation to get your own item counter up and running in no time.


Want to see Edge Impulse in action? Schedule a demo today.

Comments

Subscribe

Are you interested in bringing machine learning intelligence to your devices? We're happy to help.

Subscribe to our newsletter