Skip to content

A-matindoust/Image-Segmentation-UNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Image Segmentation using U-Net

This repository demonstrates semantic image segmentation using the U-Net architecture.

Two segmentation tasks are implemented:

  • Binary Segmentation
  • Multi-class Segmentation

The repository illustrates how encoder-decoder networks can perform pixel-wise classification by assigning a class label to every pixel in an image.


What is Image Segmentation?

Image segmentation is the task of classifying every pixel in an image.

Instead of predicting a single label for the entire image, the network predicts a segmentation mask where each pixel belongs to one semantic class.

Each training sample consists of:

  • Input image
  • Corresponding segmentation mask

Why U-Net?

U-Net is one of the most successful encoder-decoder architectures for image segmentation.

The encoder extracts increasingly abstract image features through downsampling, while the decoder reconstructs a full-resolution segmentation mask through upsampling.

Skip connections transfer high-resolution spatial information from the encoder directly to the decoder, significantly improving boundary localization and segmentation accuracy.


Binary Segmentation

Dataset

2018 Data Science Bowl (Kaggle)

The segmentation masks contain only two values:

  • Background
  • Object

The masks are normalized from:

  • 0 → 0
  • 255 → 1

Input images are also normalized before training.


Loss Function

The output layer uses a sigmoid activation.

Binary Cross-Entropy is used as the loss function because each pixel represents a binary classification problem.


Multi-class Segmentation

Dataset

People Clothing Dataset (Kaggle)

The dataset contains 59 semantic classes.

Images can be loaded in either RGB or BGR format. The choice of color format is not critical during training, but the same format must be used during inference to obtain consistent predictions.


Output Layer

The final layer uses the Softmax activation function to predict the probability of each class for every pixel.


Loss Function

Sparse Categorical Cross-Entropy is used because the segmentation masks already contain integer class labels.

Although Categorical Cross-Entropy could also be used, it requires converting every mask into one-hot encoded labels. With 59 classes, one-hot encoding significantly increases memory usage, making Sparse Categorical Cross-Entropy the more efficient choice.


Model Architecture

The implemented U-Net consists of:

  • Encoder
  • Bottleneck
  • Decoder
  • Skip Connections

Skip connections preserve fine spatial details that are often lost during downsampling, resulting in more accurate object boundaries.


Technologies

  • Python
  • TensorFlow
  • Keras
  • OpenCV
  • NumPy
  • Matplotlib

About

Binary and multi-class image segmentation using U-Net with TensorFlow/Keras.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors