SEG-PEFT is a repository for medical image segmentation research, focused on polyp detection in endoscopic images. The project explores the effectiveness of LoRA (Low-Rank Adaptation) for medical image segmentation tasks, specifically comparing full fine-tuning vs. parameter-efficient fine-tuning approaches on the Kvasir-SEG dataset.
You shall download the dataset at the following link https://datasets.simula.no/downloads/kvasir-seg.zip
The Kvasir-SEG dataset is a medical image dataset specifically designed for polyp segmentation in endoscopic images. The dataset contains:
- Images: Endoscopic images of the GI tract containing polyps
- Masks: Binary segmentation masks where the polyp regions are marked
- Size: 1000 image-mask pairs for training and validation
- Task: Semantic segmentation to identify and segment polyp regions
To use the dataset with this project, you must place it in the following directory structure:
SEG-PEFT/
├── data/
│ └── Kvasir-SEG/
│ ├── images/
│ │ ├── cju0bygl98aar07367zog10cj.jpg
│ │ ├── cju0byglb8abs073685yd3kjn.jpg
│ │ └── ... (998 more image files)
│ └── masks/
│ ├── cju0bygl98aar07367zog10cj.jpg
│ ├── cju0byglb8abs073685yd3kjn.jpg
│ └── ... (998 more mask files)
The dataset is organized in two directories:
data/Kvasir-SEG/images/: Contains the endoscopic images in RGB formatdata/Kvasir-SEG/masks/: Contains the corresponding binary masks where polyps are labeled as white (255) and background as black (0)
During training, the images are preprocessed with the following augmentations:
- Resize to 512x512 pixels
- Horizontal flipping (50% probability)
- Random brightness and contrast adjustments (20% probability)
Forst of all you must execute the following commmands to clone and install the dependencies:
git clone https://github.com/rossoc/SEG-PEFT
cd SEG-PEFT
pip install -r requirementsFurthermore, you may want to activate the environment:
source .venv/bin/activateTo train the SegFormer model without LoRA (full fine-tuning):
python scripts/train_segformer.py --epochs 30 --lr 5e-5 --save-dir my_experimentAdditional options:
--epochs: Number of training epochs (default: 30)--lr: Learning rate (default: 5e-5)--save-dir: Directory name to save the model (required)--seed: Random seed for reproducibility (default: 42)
To train the SegFormer model with LoRA (parameter-efficient fine-tuning):
python scripts/train_segformer_lora.py --epochs 30 --lr 5e-5 --rank 8 --lora-alpha 32 --lora-dropout 0.1 --save-dir my_lora_experimentAdditional options:
--epochs: Number of training epochs (default: 30)--lr: Learning rate (default: 5e-5)--rank: LoRA rank (default: 8)--lora-alpha: LoRA alpha parameter (default: 32)--lora-dropout: LoRA dropout rate (default: 0.1)--save-dir: Directory name to save the model (required)--seed: Random seed for reproducibility (default: 42)