Improving local food processing with Amazon Lookout for Vision

Olalekan Elesin
5 min readFeb 27, 2021

The announcement of Amazon Lookout for Vision at AWS Re:Invent 2020 aroused my curiosity on how I could apply this. The application, rather from real life problems I could relate with while growing up and not only from a blogpost perspective. In the past, I’d written about Amazon Web Services Computer Vision AI services:

  1. Serverless Product Recommendations with Amazon Rekognition
  2. Augment Pneumonia Chest X-ray Diagnosis with Amazon Rekognition Custom Labels

These posts, though relatable, do not speak to my growing up experiences in Ogun state, Nigeria.

We visited my grandmother during festive holidays at Ago Iwoye, also in Ogun State. This part of Ogun state, Ijebu, is popular for its edible cassava flakes, known as Garri. A staple food amongst the not so wealthy in Nigeria. Back then, I often watched the workers involved in the local processing, milling and roasting the cassava flakes. However, one of the major challenges, which still exists till date, was the infection of cassava tubers. This affects the overall output of cassava flakes that can be produced, hence, reducing the supply of this “essential commodity”.

When Amazon Lookout for Vision was announced, I asked myself if this service could help locals (and industry-scale processors) improve the quality of cassava flakes produced.

Hypothesis: What if local cassava flakes producers can leverage AI to improve the quality of their cassava flakes cheaply with zero knowledge of how AI works?

The Work

Before we proceed, one might ask: “What is Amazon Lookout for Vision”?

Amazon Lookout for Vision is a machine learning (ML) service that spots defects and anomalies in visual representations using computer vision (CV). With Amazon Lookout for Vision, manufacturing companies can increase quality and reduce operational costs by quickly identifying differences in images of objects at scale.

Tying this definition to our hypothesis, Amazon Lookout for Vision appears to be a perfect match to spot defects to improve quality cheaply.

Data Preparation

To train an Amazon Lookout for Vision model, one needs to have a minimum of 30 images: 20 images of what normal looks like and 10 images of what anomaly looks like. For this, I collected cassava images primarily from the PlantVillage website and some other websites. For this purpose of this post, I collected a hand full of quality images. However, for real life production deployment, I recommend running some data augmentation on the image dataset, increasing the number of images available for train by at least a factor of 5.

Amazon Lookout for Vision Training Image Upload — Cassava Root Images
Add data labels to images from Amazon Lookout for Vision console — Cassava Root Images

Model Training

Once dataset was ready, next was to give Amazon Lookout for Vision a spin with model training. However, my first model training failed — I mean what works the first time. The failure was due to images not having the same dimensions, this was something I never observed about when using Amazon Rekognition Custom Labels.

Amazon Lookout for Vision fails when images in dataset are not of the same dimensions

Right away, I fired up my local Jupyter environment to resize the images and uploaded the resized images to my S3 bucket. This time, I used the S3 path option to provide the training dataset to Amazon Lookout for Vision:

Import images from S3 bucket to Amazon Lookout for Vision — Cassava Root Images

Results

Amazon Lookout for Vision model metrics for Cassava Root Images

Achieving an F1 score of 80% on 31 training images, comprising of 20 normal cassava root images and 11 anomaly cassava root images is not bad for a first run. At production scale, we would be considering thousands of raw images, which we would later augment to build a really diverse dataset.

Deployment

Like Amazon Rekognition Custom Labels, Amazon Lookout for Vision pricing starts at $4 but reduces over time based on the number of inference hours.

Amazon Lookout for Vision Pricing

Hence, for my use case, assuming that my cassava quality inspection service is up for 8 hours/day and 20 working days per month, it would cost a total of $640/month. Considering the scale of potential usage for the 5th most important crop in the world, according to Forbes, the solution is well worth the price.

With regional production of 487,117 metric tons per year on a harvested area of 171,593 hectares, cassava — the fifth most important crop in the world.

Near Future Work

Amazon Lookout for Vision is yet to support model deployments on edge devices, as such we would have to look for creative ways of enabling cassava food processors to access this service. One option is to run inference via cheap Android phones, which probably might not scale. Another, which I am about to start working on, is RaspberryPi Zero with camera and WiFi/3G modules.

Can’t wait to hear what you’ll build with Amazon Lookout for Vision. You can reach me via email, follow me on Twitter or connect with me on LinkedIn.

--

--

Olalekan Elesin

Enterprise technologist with experience across technical leadership, architecture, cloud, machine learning, big-data and other cool stuff.