As the topic suggests the role of semantic segmentation involves segmenting the input image by semantic information(meaningful information) and predicting and categorizing (semantic category) each pixel into groups with specific labels(Multi-color labels).
Applications:
Semantic segmentation is used in the following fields
Robotics:
Used by machines to segregate objects like in recycling to group objects and to locate objects and boundaries.
Self-driving cars:
It provides information about free spaces, lane markings, traffic signals, and ongoing cars.
Semantic segmentation in Self-Driving cars
Biomedical imaging and diagnostics:
It's used in detecting anomalies like tumors during imaging and many other abnormalities.
Semantic segmentation in medical field
Facial recognition:
Used in computer vision applications to distinguish an individual's ethnicity, age, gender, and expressions.
Used in Aerial imagery and GeoSensing.
Precision agriculture.
Steps in Semantic Segmentation:
Classification:
Classifying objects in the input image.
Classifying the objects in the image using labels
Bounding:
Bounding the classified objects using bounding boxes.
Segmenting and Masking:
Categorizing the pixels in the localized images by creating a segmentation mask.
Masking labels on the localized image
State of art Deep Learning Methods:
Some of the Deep learning methods for semantic segmentation are:
DeepLab by Google.
Unet (Used mainly in the Biomedical industry).
Fully Convolution Network(FCN).
Semantic Segmentation using DeepLabV3+:
DeepLab is one of the best state-of-art methods used for semantic segmentation worldwide. Its open-sourced by Google since 2016 with multiple improvements and integrations as follows
DeepLabV2
DeepLabV3
DeepLabV3+
Architecture:
DeepLabV3+ Architecture
Architecture of DeepLabV3+ consists of:
Encoder
Decoder
Encoder:
ResNet101:
Part of the encoder is ResNet101(Residual Network) which is an Artificial Neural Network (ANN) of a kind that stacks residual blocks on top of each other to form a network. It is 101 layer deep and is trained with millions of data of various categories from the ImageNet database and thus consist of millions of parameters useful for image recognition.
ASPP:
Atrous convolution or dilated convolution:
It's one of the key innovations of DeepLabv3+ in Encoder. Differing from the normal convolution methods atrous convolution allows the network to have a larger effective receptive field, which means they can consider a larger context while making predictions while performing image processing.
Atrous Spatial Pyramid Pooling (ASPP):
ASPP works by applying multiple layers of Atrous convolutions at different field rates. The majority of downsampling of the images occurs in the ASPP module.
ASPP uses the spatial pyramid pooling(SPP) module, which pools the output of atrous convolutions at different field rates. This helps to capture information at different scales, which is helpful and important for semantic segmentation.
Pooling different convolution layers at different rates
The output of ASPP is then concatenated with the output of the last convolution layer(1x1) and fed into the decoder.
Let's look into the code block for building an encoder module(ASPP):
The decoder uses a combination of upsampling and convolution layers to combine the features extracted from the encoder and produce a dense segmentation map.
The decoder typically starts with an upsampling layer, which increases the spatial resolution of the feature map by inserting zeros between the values and then convolving over the result. This process is repeated several times until the spatial resolution of the feature map is the same as the input image.
Skip connections are used in the decoder, which allows the decoder to incorporate information from different scales and improve the accuracy of segmentation.
Skip connections, also known as shortcut connections, are a type of connection in neural networks that bypass one or more layers and directly connect the input of the network to a deeper layer.
Let's look at the code block for the model:
defdeeplabv3_plus(shape):""" Input """
inputs = Input(shape)
""" Encoder """
encoder = ResNet101(weights="imagenet", include_top=False, input_tensor=inputs)
image_features = encoder.get_layer("conv4_block6_out").output
x_a = ASPP(image_features)
"""Decoder"""
x_a = UpSampling2D((4, 4), interpolation="bilinear")(x_a)
x_b = encoder.get_layer("conv2_block2_out").output
x_b = Conv2D(filters=48, kernel_size=1, padding='same', use_bias=False)(x_b)
x_b = BatchNormalization()(x_b)
x_b = Activation('relu')(x_b)
x = Concatenate()([x_a, x_b])
x = SqueezeAndExcite(x)
x = Conv2D(filters=256, kernel_size=3, padding='same', use_bias=False)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Conv2D(filters=256, kernel_size=3, padding='same', use_bias=False)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = SqueezeAndExcite(x)
"""Final Masking Stage"""
x = UpSampling2D((4, 4), interpolation="bilinear")(x)
x = Conv2D(1, 1)(x)
x = Activation("sigmoid")(x)
model = Model(inputs, x)
return model
Hope you understood the working of semantic segmentation architecture. Now, let's code a simple semantic segmentation using DeepLabV3 using PyTorch, given along with the output.
With the above code, we could understand the working of semantic segmentation. Here i used a pretrained model of DeepLabV3+ using ResNet101 layer from PyTorch.