/BC-SAM

[ISBI 2024] Official PyTorch implementation of Towards Cross-Domain Single Blood Cell Image Classification via Large-Scale LoRA-based Segment Anything Model.

Primary LanguagePythonMIT LicenseMIT

BC-SAM

Official PyTorch implementation of Towards Cross-Domain Single Blood Cell Image Classification via Large-Scale LoRA-based Segment Anything Model (ISBI 2024).

Dataset

We use two different white blood cells datasets to evaluate our method:

Result

Usage

Installation

cd BC-SAM
conda create -n BCSAM python=3.9
conda activate BCSAM
pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt

How to run

step 1 : Finetune Segment anything with LoRA

Finetune Data

Train | Test

├── SAM
    ├── datasets
        ├── Bloodcell
            ├── Bloodcell_train.dat.gz
            ├── Bloodcell_test.dat.gz
python SAM/finetune_main.py \
--checkpoint model/sam_vit_b_01ec64.pth \
--datasets_dir SAM/datasets/Bloodcell \
--exit_path SAM/output

step 2 : Get image embeddings and masks

Matek-19

python SAM/sam_output.py
--path /path/to/dataset/Matek-19
--checkpoint_sam model/sam_vit_b_01ec64.pth
--checkpoint_path SAM/output/epoch_85.pth
--file_ext SAM/Matek-19.dat.gz

Acevedo-20

python SAM/sam_output.py
--path /path/to/dataset/Acevedo-20
--checkpoint_sam model/sam_vit_b_01ec64.pth
--checkpoint_path SAM/output/epoch_85.pth
--file_ext SAM/Acevedo-20.dat.gz

Here, --path is the path of the source dataset.

step 3 : Train Cross-domain Autoencode

python train.py \
--datasets_dir SAM
--model_exit model/

Here, --datasets_dir is the path of features and masks extracted from SAM.

step 4 : Classification

Run feature/classification.ipynb to get the classification results.