Note: This is an enhanced version of the original GF-SAM with key improvements for Few-Shot Segmentation.
- Targeted Segmentation: Process only specific images instead of the entire dataset.
- Better Support Images: No duplicate images in support sets.
conda create --name gfsam python=3.13.2
conda activate gfsam
# my CUDA version is 12.4
pip install torch==2.6.0 torchvision==0.21.0
pip install 'git+https://github.com/facebookresearch/detectron2.git'
git clone https://github.com/raziyev/GF-SAM-custom.git
cd GF-SAM-custom
pip install -r requirements.txt- For model weights download, see original GETTING_STARTED.md.
Download datasets using the official guide.
Organize your files exactly like this:
GF-SAM-custom/
└── datasets/
└── FSS-1000/
├── data/ # All images/masks go here
│ ├── scratch/ # Example class folder
│ │ ├── 1.jpg # Image file (numeric names only)
│ │ ├── 1.png # Mask file (white=object, black=background)
│ │ ├── 2.jpg
│ │ ├── 2.png
│ │ ... # more images
│ ├── dent/ # Another class folder
│ │ ├── 1.jpg
│ │ ├── 1.png
│ │ ├── 2.jpg
│ │ ├── 2.png
│ │ ...
│ ...
├── splits/ # Required for evaluation
│ └── test.txt # Controls which folders to process
│
└── query_file.txt # Your custom selection file (optional)
-
Images:
-
Naming:
- Only use numbers for filenames (e.g., 1.jpg, 2.png)
- No letters/symbols in filenames
-
Types:
- .jpg for input images
- .png for mask files
-
Mask Colors:
- Object: Pure white (RGB 255,255,255)
- Background: Pure black (RGB 0,0,0)
-
-
test.txt configuration:
-
This file determines which class folders to process.
-
Only folders listed in test.txt will be segmented.
-
File location:
datasets/FSS-1000/splits/test.txt- File format:
scratch dent # Add other folder names here, one per line -
-
query_file.txt configuration:
-
The
query_file.txtlets you specify exactly which images to process, rather than segmenting all images in the dataset. -
File location:
datasets/FSS-1000/query_file.txt- File format:
folder_name image_number1 image_number2 ... # (no .jpg extension)- Example:
Predicts segmentation masks only for dent/6.jpg, dent/7.jpg, dent/8.jpg and scratch/1.jpg, etc.
dent 6 7 8 scratch 1 2 3 -
-
Input Selection:
- Processes only images specified in
query_file.txt - Folders must be listed in
datasets/FSS-1000/splits/test.txt
- Processes only images specified in
-
Support Set Selection:
- Selects
--nshotunique random images from remaining (query image excluded) images in the same folder - Ensures no duplicate support images (fixed from original implementation)
- Selects
-
Output:
- Implementation log file saved to
output/fss/fold0/ - Visualizations saved to
output/vis/when--visualize 1is set
- Implementation log file saved to
-
Targeted Processing (with
query_file.txt):- Only processes specified images
- Example:
bus 6 7 8→ processesbus/6.jpg,bus/7.jpg,bus/8.jpgas query
-
Full Dataset Processing (no query file):
- Processes all images in folders listed in
test.txt - Uses all images as queries (original behavior)
- Processes all images in folders listed in
python main_eval.py \
--datapath datasets \
--benchmark fss \
--queryfile my_query.txt \ # Your custom selection (default= None)
--nshot 1 \ # 1 support image per query
--fold 0 \
--log-root "output/fss/fold0" \
--visualize 1 # Saves visualizationspython main_eval.py \
--datapath datasets \
--benchmark fss \
--nshot 1 \
--fold 0 \
--log-root "output/fss/fold0"