The Cell Segmentation Project utilizes the UNet architecture to identify and segment red blood cells (RBCs) and white blood cells (WBCs) in microscope images. This project demonstrates the application of deep learning, specifically convolutional neural networks, in medical image analysis, and is instrumental in medical diagnoses and research.
This project uses the Blood Cell Detection Dataset from Kaggle, which includes a collection of microscope images of blood cells. The dataset provides a foundation for training the model to segment and identify different types of blood cells.
To run this project, you'll need Python and TensorFlow installed on your machine.
- Python: Ensure Python is installed. Download Python.
- TensorFlow: Install TensorFlow for Python using pip:
pip install tensorflow
To use this project, follow these steps:
- Prepare Your Dataset:
- Place your microscope images from the Kaggle dataset in the
resources/images
directory. - Ensure that you have an
annotations.csv
file detailing the cell locations and labels, as provided in the dataset.
- Update File Paths:
- In the
data.py
script, update thebase_path
to your image directory if different from the default. - Update the path in
load_annotations
intrain.py
to your annotations file.
- Run the Training Script:
- Execute the
train.py
script to train the model. This script will automatically split the data, train the UNet model, and save the best model. - Optionally, adjust the
epochs
andbatch_size
in the training script as needed.
- Visualize the Results:
- After training, the script will visualize some of the segmented images showing the original, the true mask, and the predicted mask.
- data.py: Contains functions for loading and preprocessing data.
- model.py: Defines the UNet architecture.
- train.py: Handles the training, evaluation, and visualization of the model.
- resources/images/: Directory containing your microscope images.
- resources/annotations.csv: Annotations file detailing cell locations and labels.
UNet is a type of convolutional neural network (CNN) developed primarily for biomedical image segmentation. Named 'UNet' due to its U-shaped structure, it was introduced by Olaf Ronneberger, Philipp Fischer, and Thomas Brox in their paper "U-Net: Convolutional Networks for Biomedical Image Segmentation."
- Initial Convolution Blocks:
- Each block consists of two 3x3 convolutions, each followed by a rectified linear unit (ReLU).
- The first layer starts with a relatively small number of feature channels (e.g., 64), which is doubled with each subsequent downsampling step.
- These convolutional layers extract features from the image at various levels of abstraction.
- Max Pooling:
- After each convolution block, a 2x2 max pooling layer with stride 2 reduces the spatial dimensions of the feature maps.
- This downsampling process increases the receptive field, allowing the network to capture more global information from the input image.
- Feature Channel Doubling:
- As the network goes deeper, the number of feature channels doubles. This increment allows the network to learn more complex features at each level.
- For instance, if the first layer has 64 channels, the next layer after pooling would have 128, and so on.
- Transition between Downsampling and Upsampling:
- The bottleneck is the part of the network with the smallest spatial dimensions.
- It typically includes two 3x3 convolutions with ReLU activations and possibly a dropout layer.
- This section processes the most abstract representations of the input data.
- Upsampling:
- The network symmetrically expands, starting from the bottleneck.
- Upsampling (or up-convolution) is used to increase the spatial dimensions of the feature maps.
- The number of feature channels is halved with each upsampling step.
- Concatenation with Corresponding Feature Maps:
- After upsampling, the feature map is concatenated with the feature map from the corresponding level of the contracting path.
- These skip connections provide high-resolution features to the expanding path, which helps in precise localization.
- Convolution Blocks after Concatenation:
- Following each concatenation, there are two 3x3 convolutions, each followed by ReLU.
- These convolutions process the combined features from both the contracting path and the upsampling path.
- 1x1 Convolution:
- The final layer of the network is a 1x1 convolution.
- This layer is used to map the feature vectors to the desired number of classes for segmentation.
- For binary segmentation, it typically has a single output channel. For multi-class segmentation, the number of output channels corresponds to the number of classes.
-
Symmetrical Design: UNet's architecture consists of a contracting path and an expansive path, forming a U-shaped design. This structure captures context and enables precise localization.
-
Contracting Path: Involves repeated application of convolutions, ReLU activations, and max pooling for downsampling, increasing feature channels at each step.
-
Expansive Path: Includes upsampling, "up-convolutions," and concatenation with features from the contracting path, followed by convolutions and ReLU activations.
-
Skip Connections: Connect contracting path layers to expansive path layers, propagating context information to higher resolution layers.
-
Final Layer: A 1x1 convolution maps each feature vector to the desired number of classes.
UNet is widely used in biomedical image segmentation, such as segmenting cells or tissues in microscopy images, due to its precision and efficiency, especially in scenarios with limited high-quality data.
Below are some examples of the cell segmentation results. These images showcase the model's ability to accurately segment RBCs and WBCs in microscope images from the Kaggle dataset.
- This project is specifically designed for segmenting RBCs and WBCs in microscope images. Adjustments may be needed for different types of cells or imaging modalities.
- Performance and accuracy can vary based on image quality and characteristics.