X
    Categories: Blog

Materials Identification System Development at Edge

This blog illustrates leveraging Amazon SageMaker and Amazon IOT Greengrass to develop an Image Classification ML model and deploy it on the Edge to detect objects.

The Image classification ML technique is used in manufacturing and assembly units to keep track of all the parts that are used and enables packaging inspection, barcode reading, and quality inspection automatically.

AMAZON SAGEMAKER

Amazon SageMaker is a fully managed machine learning service. Users can quickly and easily build and train machine learning models, and then directly deploy them into a production-ready hosted environment managed by AWS.

AWS IOT GREENGRASS

AWS IoT Greengrass is software that extends cloud capabilities to local devices. This enables devices to collect and analyze data closer to the source of information, react autonomously to local events, and communicate securely with AWS IoT Core and export IoT data to the AWS Cloud.

SOLUTION APPROACH

Image Classification ML model can be built in AWS using the above services and deploy to the edge for inference.

TRAINING DATA

To develop the ML model, precise training data is required that helps algorithms understand certain patterns or series of outcomes. Training data must consist of concise images that resemble the production scenario, which helps the ML model to learn and perform inference with higher confidence.

DATA AUGMENTATION

Data augmentation helps to improve the performance and outcomes of an ML model by forming new and different samples to create a dataset.

The following must be remembered when training a model:

1. Data must be augmented in a way that the model learns to recognize objects and not to overfit the model with extreme accuracy.

2. The time taken to train your model for efficient training when a large training data set is available.

Below are the image augmentation techniques performed:

1. Resizing the image data set to 512*512 resolution so that the time taken to train the model can be reduced.

Original Image

Size = 5.59 MB
Dimensions = 4000*3000

Resized Image

Size = 43.8 KB
Dimensions = 512*512

2. Augmenting the training dataset with multiple angles of the same image helps in increasing the practicality of the model. The following data augmentation can be used:

a. Rotating the image by 45 degrees:

Rotated Image (45º)

Size = 43.8 KB
Dimensions = 512*512

Rotated Image (90º)

Size = 43.8 KB
Dimensions = 512*512


b. Flipping the images horizontally and vertically:

X - Flipped Image

Size = 43.8 KB
Dimensions = 512*512

Y – Flipped Image

Size = 43.8 KB
Dimensions = 512*512


c. Adding color saturation and gaussian noise to images in training data set:

Blue saturated

Size = 43.8 KB
Dimensions = 512*512

Green saturated

Size = 43.8 KB
Dimensions = 512*512

Red saturated

Size = 43.8 KB
Dimensions = 512*512

Gaussian Noise

Size = 43.8 KB
Dimensions = 512*512


TRAINING THE ML MODEL

An Amazon SageMaker Notebook instance is leveraged to train an ML model using the augmented dataset. The augmented dataset present in S3 is split into a training dataset and a validation dataset in a ratio of 9:1 after which manifest files are created. The augmented images in S3 are streamed directly (Pipe mode) to the notebook instance (as opposed to File mode, where all input files must be downloaded to disk before the training starts).

The following Hyper Parameters are utilized in training the model.

Instance = ml.p2.8x.large
Mini-batch-size = 64
Epoch = 20
Early_stopping_patience = 2
early_stopping_tolerance = 0.01
early_stopping = True
learning_rate = 0.1
lr_scheduler_factor = 0.1
lr_scheduler_step = 10,20

The Training Accuracy, Validation Accuracy and Time taken to train the model must be satisfactory. If not, the Hyperparameters must be changed accordingly to obtain satisfactory results.

LOCAL INFERENCE

The Trained Model is tested with a new set of images to determine the precision of model accuracy, and the same can be produced by batch inference. The prediction thus obtained can be utilised in developing the Confusion Matrix.

The Confusion Matrix is a performance measurement for machine learning classification. It is extremely useful for measuring Recall, Precision, Accuracy, and most importantly, AUC-ROC curves.

True Positive: Predicted positive and it’s true.
False Positive: Predicted positive and it’s false.
True Negative: Predicted negative and it’s true.
False Negative: Predicted negative and it’s false.
Recall: Predicted correctly from all positive classes.
Precision: Actual positive from all positive classes.
Accuracy: Predicted correctly from both positive and negative classes.

DEPLOYING THE MODEL TO EDGE (WAREHOUSE)

Since the ML model uses ResNet, the inference is faster due to its light weight and hence can be hosted in edge devices where compute capacity is limited. We used “EC2 – Ubuntu t3.medium (Ubuntu 18.04 OS with 30GB EBS volume)” which resonates an edge device.

The following dependencies are installed in the EC2 instance.

  • Mxnet
  • OpenCV
  • Greengrass Core software
  • IoT certificates and subscription components
  • ML model component
  • Frames
  • Greengrass SDK

Lambda component can be leveraged to perform the below functions:

  • It takes the frame as input and loads the ML model into memory for inferencing.
  • It puts the inference output into IoT analytics.

As a result, by leveraging Amazon services, the image classification ML model can be trained and deployed at the edge.

ANALYTICS

Key business decisions are made efficiently based on the quality of data available. Hence, the ability to interpret and derive meaningful insights from the processed data would help in understanding the status and goals in a more clear-cut manner.

Amazon QuickSight is leveraged for augmenting the quality of data by adding a presentation layer so that actionable information can be derived, which eventually leads to effective decision making.

BENEFITS

When machine learning and image classification get integrated, computers become capable of performing visual tasks that, until recently, could only be carried out by humans. Analysis performed by a human may cause errors due to stress, distraction, or fatigue. Computers are not prone to such causes, which may lead not only to increased precision but also to faster performance.

Machine learning for image classification is used in the following sectors:

1. Healthcare: identifying medical conditions and determining the correct treatment for them.

2. Insurance: Processing images submitted by customers to reduce the errors caused by misunderstandings.

3. Production: Monitoring machine wear and tear on the assembly line to performing quality inspections on work-in-progress and finished products.

Image classification presents new digital opportunities for companies in a variety of domains.

If you have any questions or suggestions, please reach out to us at contactus@1cloudhub.com

Written by :   Karthikeyan G  Surya Prakash K &   Umashankar N

Sharing is caring!

Comments are closed.