Edge Impulse logo
Blog Post

Making the Most of Rusty ML Skills

Computer Vision, Embedded Devices, Machine LearningBuild a computer vision model to identify rust and other corrosion of iron and steel using a handheld device.

Nick Bild

December 8, 2022

    Where there is equipment made of iron, steel, or a great many other metals, corrosion is often not far behind. Unavoidable exposure to ubiquitous elements like oxygen and moisture is enough to begin this gradual deterioration of metal. As the corrosive process continues, it will lead to a reduction in effectiveness of the impacted components, and eventually, a total failure. Such problems are particularly pronounced in industries where volatile materials are used, as is the case in the oil and gas industry. Under these conditions, component failures can lead to serious worker safety issues, explosions, and large equipment costs. Estimates indicate that the global costs incurred due to corrosion exceed a staggering $2.5 trillion each year.

    As you might imagine, given the massive magnitude of the problem, a lot of effort goes into monitoring for corrosion so that steps can be taken early to remediate the damage before it gets completely out of hand. Unfortunately, in far too many cases, that monitoring process is manually conducted by humans doing visual inspections. These types of inspections are prone to error due to the subjective opinions of inspectors, and are also highly labor intensive. Moreover, when equipment is in remote or otherwise inaccessible locations, visual inspection can be both impractical and unsafe for workers to perform.

    An automated solution that removes human subjectivity and risk to life and limb could go a long way towards eliminating the more serious consequences of advanced corrosion. If such a solution were inexpensive, power efficient, and physically small, it could be deployed far and wide to continually monitor any at-risk equipment. Drones could even be equipped with such a technology to monitor the most difficult to reach, and more dangerous, locations. We may not be very far off from a device that checks all of these boxes, as engineer Wamiq Raza recently demonstrated. He used a low-cost computing platform and Edge Impulse Studio to build a prototype system that can detect corrosion automatically, without the need for human intervention or subjectivity.

    Raza’s idea was to use computer vision and a neural network classifier to capture images of metal components and determine whether or not corrosion is present. The small, but very powerful, Seeed Studio reTerminal with a Raspberry Pi Compute Module 4 was chosen for the build, along with a Raspberry Pi Camera Module V2. The reTerminal has a 64-bit quad-core Arm Cortex-A72 CPU operating at 1.5 GHz and 4 GB of RAM to chew through even demanding machine learning algorithms that have been optimized for edge computing devices by Edge Impulse. It also has a five-inch, 720 x 1280 pixel LCD touchscreen built in that makes it easy to build slick user interfaces around the device. The Raspberry Pi camera image sensor can capture images at 1080p at up to 30 frames per second.

    Designing a machine learning-powered corrosion detector

    With the overall plan worked out, and the hardware decided upon, Raza needed to build a dataset to train the machine learning classifier. Fortunately Raza was able to avoid the difficult task of creating this dataset himself by locating a publicly available set of images. From this dataset he extracted a set of 150 images of corroded metal, and a further 150 of metal lacking corrosion. The images were uploaded to Edge Impulse Studio using the data acquisition tool, where class labels were automatically assigned based on the file names.

    Processing image data can get computationally expensive very quickly, so Raza chose a preprocessing step that resizes images to 96 x 96 pixels to begin the impulse design. Next, a step was added to extract the most important features from the image data, and finally those features were passed into a transfer learning block. The transfer learning block takes advantage of a MobileNetV2 96x96 0.2 model that has already been pretrained on a large dataset for image recognition tasks. By leaning on that knowledge already baked into the model, Raza was able to use his relatively small training dataset to build an accurate classifier. After tuning a few hyperparameters and optimization settings, the training process was started with a button click.

    Exploring the training data features

    After a short while the training process completed, and a confusion matrix was presented to assist in understanding how well the model was performing. An overall classification accuracy of better than 79% was achieved on the first pass, which is quite acceptable for proving the concept. The confusion matrix revealed that in some cases, the model was classifying samples with no corrosion as having corrosion. These misclassifications could be resolved in future iterations by supplying a larger set of training data, and perhaps tweaking the hyperparameters a bit more to find optimal settings for the task.

    Assessing the model’s accuracy

    Satisfied with the model’s performance, Raza next deployed it to the reTerminal hardware to see how it might operate in the field. This was accomplished by using the Edge Impulse CLI. After installing this tool, it was a simple matter of signing into his Edge Impulse account and selecting a project — after that the entire machine learning classification pipeline was downloaded to the device, along with a sample application that allowed the device to be tested out. This application grabs images in a loop, and classifies each one. It would be a fairly small task to extend this functionality so that it could send a SMS message, or write a record to a database, when corrosion is detected so that the appropriate people could be made aware.

    Model deployed to the Seeed Studio reTerminal

    With a bit more work, the prototype designed by Raza might one day take some of the bite out of the $2.5 trillion bill we pay each year due to the effects of corrosion. To see how easy it can be to have that type of impact on global problems, take a look at the details of Raza’s build. Do you think your machine learning skills are too rusty (pun intended) to even get started? You can always clone Raza’s public Edge Impulse project to get going.

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


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

    Subscribe to our newsletter