training.md
April 10, 2024 Ā· View on GitHub
Guideline for training SegVol
Build universal datasets
š If the 25 processed datasets in our ModelScope/éęē¤¾åŗ or HuggingFace have been downloaded, you can skip this step.
- We use the Abdomenct-12organ as demo dataset.
- After downloading the demo dataset, you need to config the script/build_dataset.sh file to set the environment vars:
$SAVE_ROOTis the save path for the post-processed datasets.$DATASET_CODEis your custom id for your dataset. We suggest you use0000,0001, ... as the dataset id.$IMAGE_DIRand$LABEL_DIRis the image directory path and label directory path of the original demo dataset.$TEST_RATIOis the ratio of preserved val/test data from the whole set.
- Set the
categoryin data_process/train_data_process.py file. Categories should be in the same order as the corresponding idx in ground truth volume andbackgroundcategory should be ignored. - Just run
bash script/build_dataset.sh.
If you want to combine multiple datasets, you can run the script/build_dataset.sh for multiple times and assign different $DATASET_CODE for each dataset.
Build pseudo mask labels
After the process of building universal datasets finished, you should build pseudo mask labels for each CT in the post-processed datasets.
- You will need to config the script/build_pseudo_mask.sh first:
$DATASET_ROOTis the directory path for the post-processed datasets.$DATASET_CODEis the custom code of your post-processed dataset.
- Run
bash script/build_pseudo_mask.sh. The pseudo masks for the$DATASET_CODEdataset will be generated at$DATASET_ROOT/$DATASET_CODE/fh_seg.
If you combine multiple datasets, you should run the script/build_pseudo_mask.sh for each dataset.
Training
- Make sure you have completed the above steps correctly.
- Set environment vars in script/train.sh:
$SEGVOL_CKPTis the weight file of SegVol.(Download from huggingface/BAAI/SegVolš¤ or Google Drive)$WORK_DIRis save path for log files and checkpoint files in the training phase.$DATA_DIRis the directory path for the above post-processed datasets.- Define dataset_codes to indicate which datasets are used for training
- Configure these parameters according to your training needs.
- Set the
$CUDA_VISIBLE_DEVICESaccording to your devices.
- Run
bash script/train.sh.
Training from scratch
If you want to training from scratch without our SegVol checkpoint, I highly recommend that you use the pre-trained ViT here and modify here to load the CLIP TextEncoder parameters.