Skip to content

fornib/FS-SAM2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FS-SAM2

This repository contains the official implementation of our ICIAP 2025 paper, FS-SAM2: Adapting Segment Anything Model 2 for Few-Shot Semantic Segmentation via Low-Rank Adaptation.

Authors: Bernardo Forni, Gabriele Lombardi, Federico Pozzi, Mirco Planamente.

FS-SAM2 Framework Overview

Results

Below are performance results for Few-Shot Semantic Segmentation (FSS) on the COCO-20i and PASCAL-5i datasets using mIoU metric, compared to other state-of-the-art models.

PASCAL results

Installation

FS-SAM2 code requires python>=3.12, with torch>=2.8.0 and torchvision>=0.23.0. Use following instructions to download the code and create a virtual environment with PyTorch:

git clone https://github.com/fornib/FS-SAM2.git && cd FS-SAM2
python3.12 -m venv .venv
source .venv/bin/activate
pip3 install torch==2.8 torchvision==0.23 --index-url https://download.pytorch.org/whl/cu126

Install SAM2 and required dependencies:

cd segment-anything2/sam2
pip install -v -e .
cd ../..
pip install peft==0.17.1 tensorboardX==2.6

Download the SAM2.1-B+ model checkpoint:

wget -P checkpoint https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_base_plus.pt

Follow VRP-SAM instruction for preparing Few-Shot Segmentation datasets: PASCAL-5i and COCO-20i.

Usage

Training:

python3 -m torch.distributed.run --nproc_per_node=$GPUs$ train.py \
        --datapath $PATH_TO_YOUR_DATA$ \
        --benchmark {coco, pascal, fss} \
        --fold {0, 1, 2, 3} \
        --epochs 50 \
        --lr 1e-4 \
        --bsz 8    

Test a given training checkpoint:

python -m torch.distributed.run --nproc_per_node=$GPUs$ test.py \
       --datapath $PATH_TO_YOUR_DATA$ \
       --benchmark {coco, pascal, fss}  \
       --fold {0, 1, 2, 3}
       --logpath $PATH_TO_YOUR_MODEL$

References

This project is mainly built based on VRP-SAM and PFENet. Thanks for their great work!

License

Code is released for non-commercial and research purposes only. For commercial purposes, please contact the authors.

About

Official PyTorch Implementation of FS-SAM2

Resources

Stars

27 stars

Watchers

1 watching

Forks

Contributors