Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BM-CELLS49 Code

Official code repository for the paper "BM-Cells49: A Fine-Grained Dataset for 49-Class Instance Segmentation of Bone Marrow Blood Cells".

Dataset figshare: BM-Cells49
Paper BM-Cells49: A Fine-Grained Dataset for 49-Class Instance Segmentation of Bone Marrow Blood Cells
Task Instance segmentation of bone marrow blood cells (49 classes)
Frameworks Detectron2 · Mask2Former

Overview

BM-CELLS49 is an open, high-resolution bone marrow smear dataset for fine-grained cell instance segmentation. It comprises 2,466 images (2736 × 1824 px, JPG) collected from 487 patients with various hematological disorders, with expert-annotated instance masks covering 49 cell types and 27,587 annotated cell instances in total. All annotations were produced by experienced hematologists through independent labeling, cross-verification, and senior-specialist adjudication. Images are released in COCO format together with an official five-fold cross-validation split stratified by patient.

To protect patient privacy, all pathology numbers were randomly shuffled and recoded as anonymized identifiers (P0001P0487); no personally identifiable information is included.

This repository contains the complete code for:

  • data preprocessing and five-fold split generation (detectron2/my_data/)
  • dataset registration and per-fold training/evaluation pipelines
  • four instance-segmentation baselines implemented in Detectron2:
    • Mask R-CNN (ResNet-101)
    • Cascade Mask R-CNN (ResNet-101)
    • Cascade Mask R-CNN (ViTDet)
    • Mask2Former (ResNet-101, with Effective Number of Samples class weighting)

Benchmark Results

Five-fold cross-validation on BM-CELLS49 (mean ± std across folds). Full experimental setup is described in the paper.

Model bbox AP bbox AP50 bbox AP75 segm AP segm AP50 segm AP75
Mask R-CNN (ResNet-101) 24.57±3.04 29.80±3.41 26.32±3.34 24.01±3.04 29.73±3.41 26.15±3.33
Cascade Mask R-CNN (ResNet-101) 25.37±3.21 29.40±3.29 26.07±3.41 24.41±3.25 29.31±3.37 26.16±3.36
Cascade Mask R-CNN (ViTDet) 28.86±3.02 32.12±2.87 29.88±2.98 28.52±2.96 32.15±2.83 29.81±2.95
Mask2Former (ResNet-101, ENS) 26.77±2.05 29.82±1.94 27.72±2.09 27.06±2.09 29.93±1.91 28.36±2.09

Repository Structure

.
├── detectron2/                    # Detectron2 (modified for BM-CELLS49)
│   ├── my_data/
│   │   ├── data_split.py          # generate per-fold COCO jsons from the 5-fold division table
│   │   ├── image_copy.py          # organize per-fold image directories
│   │   ├── data_adjust.py         # register bonecell_train_fold{i} / bonecell_val_fold{i} (imported by train_net.py)
│   │   ├── data_prof.py           # dataset statistics / profiling
│   │   ├── detect_illegal.py      # sanity checks on annotations
│   │   ├── configs/               # per-fold configs:
│   │   │   ├── bone_mask_rcnn_fold{1-5}.yaml        # Mask R-CNN
│   │   │   ├── cascade_maskrcnn_fold{1-5}.yaml      # Cascade Mask R-CNN
│   │   │   └── cascade_vitdet_fold{1-5}.py          # Cascade Mask R-CNN (ViTDet)
│   │   ├── train_fivefolds.sh     # 5-fold training loop (Mask R-CNN / Cascade)
│   │   └── train_cascade_vitdet.sh# 5-fold training loop (ViTDet)
│   ├── tools/train_net.py         # training entry (auto-registers folds via data_adjust)
│   └── output_*/ resnet_50/       # per-fold training logs and COCO metrics
├── Mask2Former/                   # Mask2Former (modified for BM-CELLS49)
│   ├── my_data/
│   │   ├── bone_cell_m2f_fold{1-5}.yaml   # per-fold configs (49 classes, ResNet-101)
│   │   ├── vit_det_fold1.yaml             # ViTDet-backbone variant
│   │   └── train_m2f_new.sh               # 5-fold training loop with ENS class weights
│   ├── predict.py                 # inference demo (cog-based)
│   └── out/ output_*/             # per-fold training logs and metrics
└── environment.yml                # conda environment of the original training machines

Installation

The code was developed and tested on Linux with CUDA 12.1.

# 1. Create the conda environment (full export of the original training environment)
conda env create -f environment.yml
conda activate medsam

# 2. Build the vendored (modified) Detectron2 from source
cd detectron2
pip install -e .

# 3. Mask2Former needs no separate installation:
#    run its scripts from the Mask2Former/ directory so that the local
#    `mask2former` package is importable.

On other platforms, the essential dependencies are: Python 3.10, torch==2.5.1+cu121, torchvision==0.20.1+cu121, the vendored Detectron2 (see detectron2/INSTALL.md), pycocotools, opencv-python, fvcore, timm, and omegaconf.

Note on hard-coded paths. Config files and scripts retain the absolute paths of the original training servers (e.g. /root/code/...). Replace them with your local paths before running (see the Data Preparation and Training sections).

Data Preparation

  1. Download the dataset from figshare. It contains the images (data1, data2), COCO annotation JSONs (annotations/), and the official five-fold division table (5-folds division).

  2. Generate the per-fold COCO files. Edit the three paths at the top of detectron2/my_data/data_split.py (excel_path, kp_train_path/kp_val_path, output_root), then run:

    python detectron2/my_data/data_split.py     # writes five_folds/fold{i}/train.json & test.json
    python detectron2/my_data/image_copy.py     # copies the corresponding images per fold
  3. Dataset registration. detectron2/my_data/data_adjust.py registers the datasets bonecell_train_fold{i} and bonecell_val_fold{i} (COCO instances, 49 classes) and is imported automatically by detectron2/tools/train_net.py. Update FOLD_ROOT in data_adjust.py and the sys.path.append(...) line in tools/train_net.py to your local my_data directory.

  4. Optional checks. data_prof.py summarizes dataset statistics and detect_illegal.py performs annotation sanity checks.

Training

All four baselines are trained with the official five-fold split (train on 4 folds, validate on 1). Remember to replace the absolute paths in the scripts/configs first.

# 1) Mask R-CNN (ResNet-101) — 5 folds
bash detectron2/my_data/train_fivefolds.sh
#    configs: detectron2/my_data/configs/bone_mask_rcnn_fold{1-5}.yaml

# 2) Cascade Mask R-CNN (ResNet-101) — 5 folds
#    configs: detectron2/my_data/configs/cascade_maskrcnn_fold{1-5}.yaml
#    (same train_net.py entry; swap the config in the loop)

# 3) Cascade Mask R-CNN (ViTDet) — 5 folds (lazy-config pipeline)
bash detectron2/my_data/train_cascade_vitdet.sh
#    configs: detectron2/my_data/configs/cascade_vitdet_fold{1-5}.py

# 4) Mask2Former (ResNet-101) with Effective Number of Samples (ENS) class weighting
bash Mask2Former/my_data/train_m2f_new.sh
#    configs: Mask2Former/my_data/bone_cell_m2f_fold{1-5}.yaml

Notes:

  • Update _BASE_, MODEL.WEIGHTS, and dataset paths inside each YAML config. Pretrained COCO weights referenced by the configs can be obtained from the Detectron2 and Mask2Former model zoos.
  • Mask2Former training expects per-fold class weights at Mask2Former/my_data/weights/fold{i}.npy (MODEL.MASK_FORMER.CLASS_WEIGHTS_PATH). These are computed from the Effective Number of Samples formula E_n = (1 − β^n) / (1 − β), w_y ∝ 1 / E_{n_y} using the per-fold category frequencies, and are not bundled in this repository.
  • Graphical inputs were fixed at 2736 × 1834 px; augmentation follows the protocols in the paper (horizontal flip + multiscale resize for the CNN baselines, large-scale jittering onto a 1024 × 1024 canvas for ViTDet / Mask2Former).

Evaluation

COCO Average Precision (bbox and mask, AP / AP50 / AP75) is computed with the Detectron2 COCOEvaluator at the end of each training run. Per-fold logs and metric files are kept under:

  • detectron2/output_maskrcnn/, detectron2/output_cascade/, detectron2/output_vitdet/, detectron2/resnet_50/
  • Mask2Former/output_new/ (contains metrics_raw.csv / metrics_summary.csv)

The means ± standard deviations over the five folds give the benchmark table above.

License & Acknowledgments

The baseline frameworks are included as vendored, modified copies:

  • Detectron2 — Apache License 2.0 (see detectron2/LICENSE)
  • Mask2Former — MIT License (see Mask2Former/LICENSE)

The BM-CELLS49 dataset is released via figshare.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages