What is Image Classification? A Guide for Beginners

Imagine that you are working for a construction site. You have a camera set up that triggers when someone drives a vehicle onto the site. Your job is to have the camera take a photo and assign a label to the vehicle that comes in. This is an important role: the site has limited space and having too many vehicles on site can be a safety hazard.

How can we solve this problem? This is where image classification comes into play.

In this article, we are going to discuss:

  1. What is single-label and multi-label image classification?
  2. In what situations is image classification useful?
  3. How does image classification compare to other computer vision algorithms?
  4. What real world use cases exist for image classification?
  5. How you can classify images with Roboflow.

Let’s get started.

What is Image Classification?

Image classification is a computer vision task where label(s) are assigned to an entire image. The label should be representative of the main contents of the image. For instance, you could have a classifier that identifies whether a bird is, or is not, a certain species or sex.

Image classification models are useful when you need to answer a question in this form:

“In what category or categories should the image be placed?”

An image classification algorithm will present multiple options alongside confidence levels. These confidence levels refer to how sure the classifier is that an image falls into a category. In production, you would take the classification with the highest confidence level and use that information to do something else (i.e. re-route an object to a different conveyor belt).

For instance, a coffee plant species detector might return a result like this:

  1. Coffea Arabica (95.001%)
  2. Coffea Robusta (4.899%)
  3. Coffea Eugenioides (0.1%)

In this case, the detector has returned three possibilities. Coffea Arabica has by far the highest confidence level. As long as the algorithm has been trained well and is working as expected, we could confidently say that the image contains Arabica coffee.

The video below explains image classification in more detail:

There are two types of image classification algorithm:

  1. Single-label classification
  2. Multi-label classification

Let’s talk about each of them.

What is Single-Label Image Classification?

Single-label image classification algorithms assign a single, specific label to an image. A single-label classifier could say that an image contains a dog or a cat, for example. Single-label classification is appropriate when you only need to detect one type of object in an image (i.e. whether an image contains a forklift, a car, or a truck).

Let’s go back to our earlier scenario where we want to determine the species of coffee plant species. This is a problem that can be solved with single-label classification. In this scenario, we only need to know the species of a coffee plant. This only requires use of a single label. The label might say “Coffea Arabica”, for example, if the coffee is of the Arabica varietal. Coffee plants cannot be two types at once, so single-label classification works well.

What is Multi-Label Image Classification?

Multi-label classification algorithms assign multiple labels to describe the contents of a whole image. For example, a multi-label classifier could say that an image contains both a forklift and people. But, the classifier cannot point out exactly where the objects are in the image.

Multi-label image classification is useful when there is more than one feature in a single image that you want to identify. Imagine you are working to implement a plant disease classification algorithm. Your algorithm needs to be able to identify both the plant type – tree or sapling, in this example – as well as whether the plant is showing symptoms of disease. This is a task suitable for multi-label image classification.

Imagine we have an image of a diseased sapling. The multi-label classifier could return that an image contains two labels: sapling and diseased. A single-label classifier, however, could only tell us whether the plant was a sapling or diseased, unless we specifically trained the algorithm to recognize diseased saplings. This would be suboptimal because disease symptoms would overlap since saplings are young trees.

Image Classification Use Cases

When might you want to use image classification? That’s a great question.

If you are looking to assign a single category to the contents of an image, a classification algorithm is a good decision.

In addition, if there are a limited set of categories in which an image can be classified, a classification algorithm is appropriate.

Consider the following scenario. You need to identify whether a banana is ripe, not ripe, or over ripe. Bananas are considered unripe if they are green, and are ripe if they are yellow. If a banana is starting to turn brown or black, the banana is considered over ripe. To humans, this identification is relatively easy. We can look at the banana and can usually make a determination.

In this scenario, an image classification algorithm would be helpful. You could set up a camera to take photos of bananas as they come in on the production line. If a banana is green, it is not yet bundled for sale in a supermarket. If a banana is yellow, it is prepared for shipment. If a banana is overripe, the banana is separated to be used in compost.

With this system, you can ensure:

  1. Your business doesn’t distribute too many bananas that are not ripe enough, which might impact day-to-day sales for some supermarket customers.
  2. Ripe bananas are sent to supermarkets which customers prefer.
  3. Overripe bananas are put to good use, reducing wastage if those bananas were to get to customers who don’t have a compost system set up.

We have just solved a real-world business problem with image classification.

How else might image classification be used? Let’s talk through a few more examples:

  • Defect detection: An image classifier could detect whether or not materials produced on a production line are or are not defective. Specific defects could be made part of the classifier (i.e. the product contains a hole, the product is cracked).
  • Not safe for work (NSFW) content moderation: An image classifier could ensure NSFW content cannot be posted on a platform that does not allow such content.
  • Leak detection: With an image classifier, you could monitor pipes throughout a factory and flag any instances where pipes are leaking.

These are a few of the many real-world applications of image classification. Remember, if you need to decide on whether the contents of an image fall into one of multiple categories, image classification can help.

How to Classify Images with Roboflow

Using Roboflow, you can classify images. First, create an account on the Roboflow website. Then, create a new project in the Roboflow dashboard.

For our example, let’s create a project that classifies sports from an image. Specifically, we want to find a label that describes whether an image contains a game of cricket, baseball, or football. In business, this could be used to build a database that aids in searching images and videos. If the sport in an image is in our list of sports we can identify, we should be given a classification; otherwise, we should get no result. Let’s call our project “Sports Classifier”.

Select the “Single-label image classification” label in the “Project Type” dropdown. Here’s how your project should look:

Let’s start by copying a sports classification dataset from Roboflow Universe, our repository of more than 100,000 open source datasets:

Next, let’s download the dataset and upload it into our new project in the Roboflow application:

We now have the data we need to perform our image classification. But, we don’t have a model yet. That’s our next step. To start classifying images, we need to train a model. To prepare to train our model, we need to:

  1. Click “Save and continue” once all of our images are in Roboflow in the page where we uploaded our images above.
  2. Select a train test split from the pop up. You should click on the Method form and then click “Split images between train/valid/test” to make sure your images are split property. 70% of images will go in your training set, 20% go in your validation set, and 10% go in your testing set.
  3. Click “Approve All” and “Add Approved to Dataset” once all of your images are uploaded to add your images to your model. Then, click “Add images”.
  4. Click the “Generate a new version” button.
  5. Now, we’re ready to train our model.

The “Generate a new version” button takes you to a page that lets you customize your new version of your model. For now, let’s leave all values the same as they are. We can click “Generate” in the final tab on the page.

Next, we need to click “Train” on the training dashboard so that Roboflow knows you are ready to train the version of the model you just created.

Now, we need to wait for our model to train. This can take anywhere from a few minutes to a few hours, depending on how large your dataset is. Make a cup of your caffeinated beverage of choice and come back to the Roboflow dashboard when you get an email notifying you that your project has been trained.

Once you have a trained model, you can start to use it. Click the “Deploy” tab, where you will see many different ways in which you can deploy your model. For this example, we’re going to upload an image from the internet and see how it is classified. Let’s upload an image of a few people playing cricket and see what happens:

Our image has been given the label “cricket” with a confidence rate of 95%. Our image classification model is working!

Using this same approach, you can generate classification models for a vast range of different problems, from detecting defects in a production pipeline to classifying animals that are found on a farm.

Now you have the skills you need to generate an image classification model. If data does not already exist for your problem, however, you will need to annotate images yourself. To find out more about how to do this, check out our image annotation tutorial.

Image Classification Compared to Other Algorithms

Image classification is only one of many key algorithms used in computer vision. Indeed, while image classification is immensely useful and practical for some problems, in other instances there are more suitable algorithms to use. Let’s discuss how image classification compares to other algorithms.

Image Classification vs. Object Detection

Both image classification and object detection algorithms assign labels based on the contents of an image. However, image classification labels a whole image, whereas object detection algorithms can label specific instances of objects in an image.

Imagine you need to find all of the boxes in an image to make sure there are not too many on a construction pallet. Image classification could only tell you boxes are on the pallet. That is not helpful information in this context. Object detection, however, could tell you where all of the boxes are. You can count each instance of a box to see how many boxes there are in the view of the camera.

Image Classification vs. Instance Segmentation

Like image classification, instance segmentation returns a label determined by the contents of an image. Unlike image classification, segmentation algorithms add a label to the exact pixels where the instance of an object is located in an image.

Imagine you want to identify not only that a product contains a screw that has not been screwed in properly, but the exact location of the screw in the image where the defect has been highlighted. This is possible with instance segmentation. With instance segmentation, the screw that has not been screwed in properly will be highlighted so you can see the exact location of the defect in the image.

Conclusion

Image classification is useful for solving problems where you need to classify an object into one of multiple groups. This computer vision algorithm has wide uses across industries, from content moderation to defect monitoring.

With the information we have discussed thus far, you now have the information you need to explain instance segmentation, the types of problems that are best solved with instance segmentation, and how it compares with a few other computer vision algorithms.