All Posts

How to do Multiclass Image Classification with Data Augmentation?


Humans have the capability to recognize images, patterns, objects, etc. and make meaning out of it. On the other hand, machines don't have the same ability. To solve this problem image classification using deep learning came into being. Read ahead to learn more about this technique and its applications.

[7 min read]
VisionERA
We, as humans, can easily identify things we see every day. Just by looking at a picture, we can tell what the picture depicts and if it is abstract or if it has any interesting objects or things. Let's say greenery and a fence with animals, and it's a countryside farm. Lots of white chunks spread across blue color and a white pointed elongated object with wings; undoubtedly, it's an airplane flying in the sky amongst huge clouds. As young kids, we all learn this skill easily, which comes naturally to us after a while. This particular skill of identifying the image and its contents is called Image Classification. With Artificial Intelligence, we try to reach this exact skill to machines. However, machines can't see the way we humans tend to perceive things and objects. They don't see the images the same way we people do. So, teaching the machines to identify images is quite a challenging task. This is where Deep learning comes to the rescue.

Image Classification in Deep Learning


Image Classification can be considered as a process in which a computer can analyze and understand the category an image could belong to. We use different algorithms to train various models that help a machine analyze an image and make predictions like us. However, machines can achieve this by providing the probability of the category as a prediction. These categories are called labels or classes. There are two types of image classification- single label or binary (Yes/No type) and multiclass (more than two categories).

Now, why do machines need to classify images? This brings us to the business perspective of Image Classification and why using image classification is required in different sectors worldwide. One of the crucial applications of Image classification is in the healthcare sector to improve disease detection and prognosis. Medical professionals use AI, i.e., image classifiers, to detect the onset of diseases in patients. The images used could be X-rays, MRI, or CT scans, which the computers can analyze to detect and classify any persisting health issues. Another significant application of Image Classification is in the agriculture domain, where various images of different varieties of crops are analyzed for diseases to prevent damage to the crops and improve the yield. Image Classification is also used in the manufacturing industry for visual inspection of the products and defect detection. Similarly, government agencies use image classification to study the changing climate and take preventive steps in case of likely disasters. Thus, there is a notable demand for image classification in the industry.

Requirement of Image Classification


We humans most often classify images easily and quickly. But machines, on the other hand, cannot do so without training. The computer relies on the information in the image pixels to identify an image. Previously, when images were classified, they had to rely on raw pixel data, i.e., each image would have to be broken down into a number of pixels to identify. The challenge with this was that two same images could appear quite different in pixelated formats. Their backgrounds or orientations would not be the same. This poses a great difficulty in teaching image classification to the machines. This is where Deep Learning steps in to help machines learn to classify images into correct categories.

What is Data Augmentation?


With a relatively small size dataset, both machine learning and deep learning models often suffer from the problem of 'overfitting' where training accuracies are high while test accuracies are poor. One way to address this challenge is to increase the size of the dataset. This way, the model can be trained on more number observations which can result in better generalization. However, additional data is not always available and accessible. Think of healthcare and the recent pandemic. Acquiring additional data requires time and money. Hence, data scientists often use the 'Data Augmentation' process to expand the existing data set artificially. Several techniques in this process can be used to generate additional data for training purposes. Models trained on smaller datasets can significantly benefit from data augmentation as it increases the model accuracy. We can employ data augmentation in both machine learning and deep learning models. Image, text, audio, and video data can be augmented using different available python frameworks like PyTorch, TensorFlow, and Keras. Moreover, multiple open-source tools are available, especially for data augmentation.

How does Data Augmentation help in Image Classification?


When a machine learning or a deep learning model is trained on a smaller dataset, the ability of the model for prediction is limited by the number of available training images. In other words, the model will likely fail when tested on the same object with a different orientation. This is because the model was not exposed to multiple observations of the same object. To overcome this issue, we can always aim to train the model on a higher number of images. But this is not always possible. Gathering more data is a demanding task. It can sometimes be restricted due to location, privacy laws, or just plain unavailability of more data in a specific field, such as health care, where sufficient past data for rare diseases is often unavailable.

In such cases, data augmentation using python libraries can be a good solution. One thing to note here is that although there are various techniques for Data Augmentation, not all are relevant to a particular use case at a time. A cautious approach in selecting the best relevant techniques can help avoid training the model on non-relevant images.

Techniques of data augmentation


The image data can be augmented using various techniques. Some of them are:

A. Geometric transformations such as flipping, cropping, rotating, zooming, etc.

1. Flipping


Using this method, we can flip the image horizontally and vertically.

’flipping’

2. Rotation


We can rotate the image between 0 to 360 degrees, and each rotated image in the model is unique. ’Rotation’

3. Cropping

In this method, a portion of an image is cropped and then enlarged to its original size.

’cropping’
B. Color transformations such as adjusting brightness, darkness, sharpness, saturation, etc.

1. Brightness

The brightness of the image is modified to provide a brighter or darker augmented image, allowing the model to recognize the same object in varied lighting conditions.

’brightness’

2. Color Augmentation


To modify the color of the image, the pixel values are changed (BGR2RGB and BGR2HSV).

’color

3. Saturation


The original image's depth or color intensity is altered. It increases the intensity of the specified color, as demonstrated in the image below.

’saturation’

Image Data Augmentation Tools


imgaug


Imgaug is an open-source python package for augmenting images in machine learning. It includes a variety of augmentation techniques and can augment images, landmarks, bounding boxes, heatmaps, and segmentation maps.

Albumentations


Albumentations is a fast and popular python library that integrates with popular deep learning frameworks such as PyTorch (a part of eco-system) and TensorFlow. It can perform computer vision tasks like classification, semantic & instance segmentation, object identification, and posture estimation. It is widely used in industry, deep learning research, machine learning contests, and open-source projects.

Augmentor


Augmentor is an augmentation package for machine learning that is platform and framework independent. Images are passed through a pipeline, where each operation is applied to the image as it passes through. Each operation is controlled by a probability value, which decides how an operation will be performed on an image when it passes through the pipeline.

Example of Multiclass Image Classification using Augmentor


We will consider a use case of data augmentation in Agriculture and how data augmentation can help to improve model accuracy. To demonstrate this, we will use the small dataset of grapevine leaves, which contains five classes of grapevine leaves (Ak, Ala Idris, Büzgülü, Dimnit, and Nazli). This is a small dataset of 500 images.

’grapevine
Next, we will set up a simple CNN model for image classification on this 500 images dataset. After running the model, we get a training accuracy of 56% and a validation accuracy of 77.5%. Further, we will set up an image augmentation pipeline using the Augmentor library. This will augment the images dataset to 2500 images. Now we will re-train the model with the augmented dataset.

After re-training the model, we will also plot the model performance parameters, i.e., accuracy and loss. We are getting the training accuracy of 87.15% and validation accuracy of 96.43% now.

’graph
Thus, we can say that the accuracy has improved after using augmentation.

Next, Gradio can be used to deploy the trained image classification model into an interactive application.

’gif
The entire code for this demo and the data augmentation techniques are available on GitHub.

Factors to consider in Image Classification


Undoubtedly, businesses can greatly benefit from implementing image classification tools. But when making this decision, it is important to consider the following aspects of the tool-

  • How easy is it to set up the tool? Is it possible to integrate with the tools already in use?
  • Are the tool's predictions accurate enough for the use case? E.g., Image tagging applications on a photo website might be forgiving sometimes, but not in the healthcare domain, where a false prediction could result in an inaccurate diagnosis.
  • Is the model adaptive, i.e., can it learn from its mistakes and improve in due course of time?
  • Is the tool fast enough to process an expected number of images within a specific time?
  • And most importantly, can this tool be updated and scaled as the business grows?

The answers to the above questions can help choose a correct image classification solution that can prove beneficial and improve business performance.

Conclusion


Wrapping up, we can say that image classification is an important application of AI. Predicting labels of images accurately is essential in many applications like health care, insurance, manufacturing, etc. For accurate predictions, businesses can rely on data augmentation to improve image classification tasks. In situations where limited data is accessible, data augmentation can certainly boost the accuracy of the tool/model's predictions, but it still needs to be used with caution. Hence, selecting the right tool is one of the most crucial steps. A lot of progress has been made until now, and continuous research and developmental work being done by the community, startups, and big IT giants augurs well for further success in this interesting and challenging area. We can hope further advances will contribute to the overall welfare of human beings in their lives.

About us: Looking for a document processing solution that uses the enhanced capabilities of image classification using deep learning. VisionERA Intelligent Document Processing (IDP) platform is capable of handling documents from a wide range of sources, templates, fonts, and structure because of data augmentation for image classification. It has the capacity to extract and validate data for bulk volumes with minimal intervention. Also, the platform can be molded as per requirements for any industry and use case because of its custom DIY workflow feature. It is a scalable and flexible platform providing end-to-end document automation for any organization.

You can setup a demo by clicking on the CTA below. To send us a query use the contact us page!

Try Now!

RELATED BLOGS

Tags
What is Image Classification?
Image Classification in Deep Learning
Requirement of Image Classification
What is Data Augmentation?
Techniques of Data Augmentation
Image Data Augmentation Tool
Factors to consider Image Classification
Share this article
SO, WHAT WOULD YOU WANT  
TO AUTOMATE TODAY?
REQUEST A DEMO
AmyGB.ai - Do More With Less