Implementation of 《DenseSAM: Semantic Enhance SAM For Efficient Dense Object Segmentation》(IJCAI 2025)
DenseSAM replaces location-based prompts with semantic guidance for automatic segmentation in dense scenarios, achieving remarkable performance with only ~3M training parameters. It offers a cost-effective and efficient solution for adapting SAM to dense object segmentation.
Create conda env
conda create -n densesam python=3.10
conda activate densesam
Clone codes and install dependences
git clone https://github.com/imAzhou/DenseSAM.git
cd DenseSAM
pip install -r requirements.txt && pip install -e .
You can access detailed information and download the corresponding datasets via the links provided in the table below.
Cell Datasets | Building Datasets |
---|---|
CoNIC [paper download link] | WHU [paper download link] |
CPM17 [paper download link] | Inria[paper download link] |
MoNuSeg [paper download link] | Massachusetts[paper download link] |
All datasets have been processed into a unified format. Please refer to the processing scripts for each dataset located in the process_datasets/ directory:
# For semantic dataset which no need boundary,like whu,inria and massachusetts.
Step 1: python process_datasets/whu/init_ann.py
Step 2: python process_datasets/whu/gene_coco_panoptic.py
# For instance dataset which need boundary,like conic,cpm17 and monuseg.
Step 1: python process_datasets/conic/create_init_ann.py
Step 2: python process_datasets/conic/gene_coco_panoptic.py
Step 3: python process_datasets/conic/gene_boundary_map.py
Minor differences may exist in the processing of different datasets. For details, please refer to the preprocessing code in each subdirectory under the process_datasets/ directory.
After configuring the path to your dataset in config/datasets/dataset_name.py, you can use the following script to preview the dataset and its annotations to verify that the preprocessing has been performed correctly:
python process_datasets/browse_dataset.py \
configs/datasets/conic.py \
visual_results/gt_visual/conic \
--vis_nums 5 \
--show_bbox
python scripts/train.py \
densesam/configs/datasets/conic.py \
--record_save_dir logs/conic \
--print_interval 20 \
--device cuda:1
python scripts/test.py \
logs/conic/2025_01_21_04_31_16/config.py \
logs/conic/2025_01_21_04_31_16 \
logs/conic/2025_01_21_04_31_16/checkpoints/best.pth \
--visual_pred \
--draw_func draw_cell_color \
--visual_interval 1 \
--seed 666
python scripts/inference_nometric.py \
logs/conic/2025_01_21_04_31_16/config.py \
logs/conic/2025_01_21_04_31_16 \
logs/conic/2025_01_21_04_31_16/checkpoints/best.pth \
imgset_dir \
--visual_interval 1
If you have any questions, please contact us via email: zhoulyaxx@zju.edu.cn