Original article was published on Deep Learning on Medium
Build your First Multi-Label Image Classification Model with Neural Network.
Acculturate first image classification model with python
What is Multi-Label Image Classification?
Let’s understand the concept of multi-label image classification with an intuitive example. Check out the below image:
The object in image 1 is a Bike. That was a no-brainer. Whereas, there is no car in image 2 — only a house. Can you see where we are going with this? We have classified the images into two classes, i.e., Bike or non-Bike.
How is Multi-Label Image Classification different from Multi-Class Image Classification?
Suppose we are given images of animals to be classified into their corresponding categories. For ease of understanding, let’s assume there are a total of 4 categories (cat, dog, rabbit and parrot) in which a given image can be classified. Now, there can be two scenarios:
- Each image contains only a single object (either of the above 4 categories) and hence, it can only be classified in one of the 4 categories
- The image might contain more than one object (from the above 4 categories) and hence the image will belong to more than one category
Let’s understand each scenario through examples, starting with the first one:
Here, we have images which contain only a single object. The keen-eyed among you will have noticed there are 4 different types of objects (animals) in this collection.
Each image here can only be classified either as a cat, dog, parrot or rabbit. There are no instances where a single image will belong to more than one category.
Steps to Build your Multi-Label Image Classification Model
Now that we have an intuition about multi-label image classification,
problem : we have some image data of Natural Scenes around the world. we need to classify according in to their labels .
let’s dive into the steps you should follow to solve such a problem.
Let’s import some basics python packages for images processing .
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from random import randint
load the train and test data and resize size into 75×75 pixels
for img_name in train.image_name:
train_x=np.asarray(temp)temp = 
for img_name in test.image_name:
img_path = os.path.join(file_path, 'train', img_name)
img = cv2.imread(img_path)
img = cv2.resize(img, (75, 75))
test_x = np.asarray(temp)
Normalize the image data
let’s visualize some images
Let’s convert the labels into onehot encoder
from keras.utils import to_categorical
let’s split the train into training and validation.
from sklearn.model_selection import train_test_split
let’s import the keras necessary libraries for models building .
import tensorflow.keras.layers as Layers
import tensorflow.keras.activations as Actications
import tensorflow.keras.models as Models
import tensorflow.keras.optimizers as Optimizer
import tensorflow.keras.metrics as Metrics
import tensorflow.keras.utils as Utils
from keras.utils.vis_utils import model_to_dot
from keras import regularizers
from keras.layers import BatchNormalization
model building :
let’s add the CNN layers
model = Models.Sequential()
let’s train the model
I trained model I got 87% accuracy.
If we want to increase your accuracy
fellow this blogs :