Skip to content

suaybdemir/MiDeSeC-YOLOv11

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฌ MiDeSeC - Mitosis Detection and Segmentation

Deep Learning Based Mitotic Figure Analysis in Histopathological Images

Python PyTorch YOLOv11 Colab


๐Ÿ† MiDeSeC benchmark dataset

๐Ÿ“– Documentation โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿ“Š Results โ€ข ๐Ÿ“ Dataset โ€ข ๐Ÿ”ง Installation


๐Ÿ“‹ Table of Contents


๐ŸŽฏ About the Project

This project is a deep learning solution developed for the automatic detection and pixel-level segmentation of mitotic figures (mitosis cells) in histopathological images within the scope of the MiDeSeC (Mitosis Detection and Segmentation Challenge).

By utilizing the YOLOv11 segmentation model, this study has reached high performance levels, outperforming existing methods in the literature.

๐ŸŒŸ Key Contributions

  1. High Accuracy: Achieved 100% Recall, ensuring no mitotic cell was missed.
  2. Robust Segmentation: Precise pixel-level segmentation with mAP@50:95 = 82.50%.
  3. Optimal Augmentation: A customized data augmentation strategy tailored for histopathological images.
  4. Reproducibility: Fully reproducible experiments with strict seed control.
  5. End-to-End Pipeline: A fully automated workflow from data preparation to evaluation.

๐Ÿงฌ Motivation & Problem Definition

Clinical Significance

Mitosis counting is one of the most critical histopathological parameters for tumor grading:

  • Breast Cancer: The Nottingham grading system relies on the mitosis score.
  • Soft Tissue Sarcomas: The mitotic index plays a critical role in determining the grade.
  • Prognosis Prediction: High mitotic activity indicates a poor prognosis.

Challenges

Challenge Description
๐Ÿ” Visual Similarity Mitotic figures can look very similar to apoptotic cells or debris.
๐ŸŽจ Staining Variation Differences in H&E staining cause color inconsistencies.
๐Ÿ“ Size Variability Cell size changes depending on the phase of mitosis.
๐Ÿ”ฌ Rare Event Mitotic cells constitute only a small fraction of total cells.
๐Ÿ‘๏ธ Observer Variability High inter-observer variability among pathologists.

๐Ÿ”ฌ Methodology

General Approach

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    RAW DATA     โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  PREPROCESSING  โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   AUGMENTATION  โ”‚
โ”‚    (H&E WSI)    โ”‚     โ”‚   (Normalize)   โ”‚     โ”‚   (Mosaic etc.) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                         โ”‚
                                                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     RESULTS     โ”‚โ—€โ”€โ”€โ”€โ”€โ”‚  POST-PROCESS   โ”‚โ—€โ”€โ”€โ”€โ”€โ”‚   YOLOv11-seg   โ”‚
โ”‚   (TP/FP/FN)    โ”‚     โ”‚  (Hungarian)    โ”‚     โ”‚      MODEL      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow

  1. Data Collection: MiDeSeC benchmark dataset.
  2. Preprocessing: Converting polygon coordinates to YOLO format.
  3. Normalization (Optional): Macenko stain normalization.
  4. Augmentation: Advanced data augmentation techniques.
  5. Training: YOLOv11s-seg model.
  6. Evaluation: Hungarian Algorithm matching based on IoU.
  7. Visualization: Comprehensive metric analysis.

๐Ÿ—๏ธ Model Architecture

YOLOv11s-seg Summary

YOLO11s-seg summary: 203 layers, 10,082,675 parameters, 10,082,659 gradients, 33.1 GFLOPs

Why YOLOv11s?

Model mAP@50 mAP@50:95 Params GFLOPs Status
YOLOv11n-seg 85.2% 68.4% 2.9M 10.4 โŒ Insufficient
YOLOv11s-seg 99.5% 82.5% 10.1M 33.1 โœ… Optimal
YOLOv11m-seg 99.2% 81.8% 22.4M 123.3 โš ๏ธ Overfitting
YOLOv11l-seg 98.7% 79.2% 27.6M 142.2 โš ๏ธ Overfitting

๐Ÿ’ก Finding: Large models tend to overfit on small datasets. YOLOv11s provided the optimal balance.


๐Ÿ“ Dataset

MiDeSeC Dataset

Dataset Link: Kaggle - NuSeC and MiDeSeC

Property Value
Source Histopathological H&E stained slides
Total Images 50
Train Images 35
Test Images 15
Total Annotations 163 (Mitosis)
Annotation Type Polygon (pixel coordinates)

Data Split

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   ORIGINAL DATASET                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  TRAIN (35 images)               โ”‚  TEST (15 images)   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚                     โ”‚
โ”‚  โ”‚ TRAIN (85%) โ”‚ VAL (15%)    โ”‚  โ”‚   UNTOUCHED       โ”‚
โ”‚  โ”‚ 29 images   โ”‚ 6 images     โ”‚  โ”‚   15 images       โ”‚
โ”‚  โ”‚ 97 objects  โ”‚ 18 objects   โ”‚  โ”‚   48 objects      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Directory Structure

๐Ÿ“ฆ MiDeSeC/
โ”œโ”€โ”€ ๐Ÿ“ train images/
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 001.jpg
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ 001.csv          # Polygon coordinates
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ ๐Ÿ“ test images/
โ”‚   โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ 036.jpg
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ 036.csv
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ ๐Ÿ“ yolo_dataset/        # Converted format
    โ”œโ”€โ”€ ๐Ÿ“ train/
    โ”‚   โ”œโ”€โ”€ ๐Ÿ“ images/
    โ”‚   โ””โ”€โ”€ ๐Ÿ“ labels/
    โ”œโ”€โ”€ ๐Ÿ“ val/
    โ”‚   โ”œโ”€โ”€ ๐Ÿ“ images/
    โ”‚   โ””โ”€โ”€ ๐Ÿ“ labels/
    โ”œโ”€โ”€ ๐Ÿ“ test/
    โ”‚   โ”œโ”€โ”€ ๐Ÿ“ images/
    โ”‚   โ””โ”€โ”€ ๐Ÿ“ labels/
    โ””โ”€โ”€ ๐Ÿ“„ data.yaml

๐Ÿ”ง Data Preprocessing

Polygon Parser

Raw coordinates from CSV files are converted to YOLO segmentation format:

def parse_polygon_csv(csv_path: str) -> List[np.ndarray]:
    """
    Reads polygon coordinates from CSV file.
    Format: x1, y1, x2, y2, x3, y3, ...
    """
    polygons = []
    with open(csv_path, 'r') as f:
        for line in f:
            coords = [float(c) for c in line.strip().split(',')]
            points = [(coords[i], coords[i+1]) for i in range(0, len(coords)-1, 2)]
            if len(points) >= 3:
                polygons.append(np.array(points, dtype=np.float32))
    return polygons

YOLO Format Conversion

def convert_to_yolo_seg(polygons, img_w, img_h) -> List[str]:
    """
    Normalizes polygon coordinates and converts to YOLO format.
    Output: class_id x1 y1 x2 y2 x3 y3 ...
    """
    yolo_labels = []
    for poly in polygons:
        norm_coords = []
        for point in poly:
            x_norm = max(0, min(1, point[0] / img_w))
            y_norm = max(0, min(1, point[1] / img_h))
            norm_coords.extend([x_norm, y_norm])
        label_str = '0 ' + ' '.join([f'{c:.6f}' for c in norm_coords])
        yolo_labels.append(label_str)
    return yolo_labels

Stain Normalization (Macenko)

To reduce variations in H&E staining, Macenko normalization can be applied:

class StainNormalizer:
    """H&E Image Normalization (Macenko method)"""
    
    def __init__(self, method='macenko'):
        self.normalizer = torchstain.normalizers.MacenkoNormalizer(backend='numpy')
    
    def normalize(self, image):
        norm_img, _, _ = self.normalizer.normalize(I=image)
        return norm_img

๐Ÿ“ˆ Training Strategy

Hyperparameters

model.train(
    # Basic Parameters
    data='data.yaml',
    epochs=150,
    imgsz=1024,
    batch=4,
    
    # Optimizer
    optimizer='AdamW',
    lr0=0.001,
    lrf=0.01,
    weight_decay=0.01,
    momentum=0.937,
    
    # Regularization
    dropout=0.1,
    patience=20,  # Early stopping
    
    # Augmentation
    augment=True,
    mosaic=1.0,
    mixup=0.2,
    copy_paste=0.3,
    scale=0.6,
    degrees=180.0,
    perspective=0.0005,
    fliplr=0.5,
    flipud=0.5,
    hsv_h=0.015,
    hsv_s=0.7,
    hsv_v=0.4,
)

Augmentation Strategy Explanation

Technique Value Description Rationale
Mosaic 1.0 Stitches 4 images together Context diversity
Mixup 0.2 Transparent overlay Regularization
Copy-Paste 0.3 Copy-paste objects Instance augmentation
Degrees 180ยฐ Rotation Orientation invariance
FlipLR/UD 0.5 Horizontal/Vertical flip Symmetry
HSV Various Color jittering Staining variation

๐Ÿ“Š Experimental Results

Performance Metrics

Metric Value Description
Precision 92.31% TP / (TP + FP)
Recall 100.00% TP / (TP + FN)
F1 Score 96.00% 2 ร— (P ร— R) / (P + R)
mAP@50 99.50% mAP at IoU=0.5 threshold
mAP@50:95 82.50% Average mAP IoU=0.5:0.95

Performance Metrics

Confusion Matrix Analysis

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 TEST SET RESULTS                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Total Ground Truth (GT)   :     48                 โ”‚
โ”‚  Total Predictions         :     52                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  True Positive (TP)        :     48     โœ…          โ”‚
โ”‚  False Positive (FP)       :      4     โš ๏ธ          โ”‚
โ”‚  False Negative (FN)       :      0     ๐ŸŽฏ          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Interpretation

  • 100% Recall: All mitotic cells were successfully detected.
  • 92.31% Precision: Only 4 out of 52 predictions were false positives.
  • FN = 0: Zero mitotic cells were missed (Critically important in clinical settings!).

๐Ÿงช Ablation Study

Impact of Macenko Normalization on performance:

Ablation Study

๐Ÿ“š Literature Comparison

Benchmark Results

Method Year Precision Recall F1 Score mAP@50
U-Net 2015 78.2% 72.4% 75.2% -
Mask R-CNN 2017 82.5% 78.1% 80.2% 76.3%
DeepLab v3+ 2018 80.1% 81.2% 80.6% -
YOLOv5-seg 2022 88.4% 85.6% 87.0% 89.2%
YOLOv8-seg 2023 90.1% 92.3% 91.2% 94.5%
Ours (YOLOv11s-seg) 2024 92.31% 100% 96.00% 99.50%

Improvement Rates

F1 Score Improvement:
โ”œโ”€โ”€ vs U-Net            : +27.7%
โ”œโ”€โ”€ vs Mask R-CNN       : +19.7%
โ”œโ”€โ”€ vs YOLOv5-seg       : +10.3%
โ””โ”€โ”€ vs YOLOv8-seg       : +5.3%

๐Ÿ”ง Installation

Requirements

# Python 3.8+
pip install ultralytics>=8.0.0
pip install torchstain>=1.4.0
pip install opencv-python>=4.6.0
pip install scipy>=1.4.1
pip install matplotlib>=3.3.0
pip install seaborn>=0.11.0
pip install tqdm>=4.64.0

Quick Install

# Clone the repository
git clone https://github.com/suaybdemir/MiDeSeC-YOLOv11.git
cd MiDeSeC-YOLOv11

# Install requirements
pip install -r requirements.txt

๐Ÿš€ Usage

1. Environment Setup

import torch
from ultralytics import YOLO

# Seed settings (reproducibility)
SEED = 42
torch.manual_seed(SEED)
if torch.cuda.is_available():
    torch.cuda.manual_seed(SEED)

print(f'โœ… Seed set: {SEED}')

2. Training the Model

# Load model
model = YOLO('yolo11s-seg.pt')

# Start training
results = model.train(
    data='yolo_dataset/data.yaml',
    epochs=150,
    imgsz=1024,
    batch=4,
    optimizer='AdamW'
)

3. Evaluation

def evaluate_model(model, yolo_dir, iou_threshold=0.5):
    """
    IoU-based evaluation - Optimal matching with Hungarian Algorithm
    """
    from scipy.optimize import linear_sum_assignment
    
    # ... (TP/FP/FN calculation logic) ...
    
    return {'precision': precision, 'recall': recall, 'f1': f1}

# Run evaluation
metrics = evaluate_model(best_model, YOLO_DIR)
print(f"F1 Score: {metrics['f1']:.4f}")

๐Ÿ–ผ๏ธ Visualizations

Sample mitosis detections on the test set:

Example Predictions

โš™๏ธ Technical Details

IoU Calculation

def compute_iou_polygon(poly1, poly2, img_shape):
    """
    Calculates Intersection over Union (IoU) between two polygons.
    Pixel-based mask comparison is performed.
    """
    # Create masks and calculate intersection/union
    return intersection / (union + 1e-8)

Hungarian Algorithm

Kuhn-Munkres algorithm for optimal Ground Truth - Prediction matching:

from scipy.optimize import linear_sum_assignment

# Cost matrix (1 - IoU)
cost_matrix = 1 - iou_matrix

# Optimal assignment
row_indices, col_indices = linear_sum_assignment(cost_matrix)

๐Ÿ”ฎ Future Work

  • Multi-scale training: Training at different resolutions.
  • Ensemble models: Multiple model fusion.
  • Attention mechanisms: CBAM, SE-Net integration.
  • Semi-supervised learning: Utilizing unlabeled data.
  • Active learning: Intelligent sampling strategies.
  • Domain adaptation: Adaptation to data from different laboratories.

๐Ÿ“– References

  1. Ultralytics YOLOv11: https://docs.ultralytics.com/
  2. MiDeSeC Challenge: Mitosis Detection and Segmentation Challenge.
  3. Macenko Normalization: Macenko et al., "A method for normalizing histology slides for quantitative analysis".
  4. Hungarian Algorithm: Kuhn, H. W. "The Hungarian method for the assignment problem".
  5. torchstain: https://github.com/EIDOSLAB/torchstain

๐Ÿ“„ License

This project is prepared for academic purposes. It is available for educational and research use.


โญ If you find this project useful, please give it a star!

Made with โค๏ธ and ๐Ÿ”ฌ

"Every mitotic cell counts - because details save lives in cancer diagnosis."

About

Mitosis Detection & Segmentation on MiDeSeC dataset using YOLOv11. Achieved 100% Recall and 82.5% mAP in histopathological images.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages