MIC-DKFZ / nnUNet

Apache License 2.0
5.34k stars 1.63k forks source link

How to fine-tune the pretrained model? #2229

Open SiruLiu645 opened 1 month ago

SiruLiu645 commented 1 month ago

hello, I'm trying to fine-tune my pretrained model trained by my own dataset, but I don't know what is SOURCE_PLANS_IDENTIFIER and TARGET_PLANS_IDENTIFIER,can you help me? image

mrokuss commented 1 month ago

Hey @SiruLiu645

nnUNet is always designing a specific network for a specific dataset. That means in order to pretrain and finetune these networks need to be the same. Since you are interested in the target dataset you have to let nnUNet design a network architecture for that

nnUNetv2_plan_and_preprocess -d TARGET_DATASET

and use this network also for training on the pretraining dataset. You also need to extract the fingerprint of the source dataset:

nnUNetv2_extract_fingerprint -d SOURCE_DATASET

Then you can take the plans from the target dataset and transfer it to the source:

nnUNetv2_move_plans_between_datasets -s TARGET_DATASET -t SOURCE_DATASET -sp TARGET_PLANS_IDENTIFIER -tp SOURCE_PLANS_IDENTIFIER

If you do everything in default settings SOURCE_PLANS_IDENTIFIER is just nnUNetPlans. sp and tp are mixed up in the docu, I'll fix that. See also the help:

  -s S        Source dataset name or id
  -t T        Target dataset name or id
  -sp SP      Source plans identifier. If your plans are named "nnUNetPlans.json" then the identifier would be nnUNetPlans
  -tp TP      Target plans identifier. Default is None meaning the source plans identifier will be kept. Not recommended if the source plans identifier is a default nnU-Net identifier such as nnUNetPlans!!!

Hope this helps!

Merom99 commented 5 days ago

Hi Morkuss,

I tried to follow the same steps here in this link https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/pretraining_and_finetuning.md, but I think here the source data is the pretrained data.. However when running this command: nnUNetv2_move_plans_between_datasets -s PRETRAINING_DATASET -t TARGET_DATASET -sp PRETRAINING_PLANS_IDENTIFIER -tp TARGET_PLANS_IDENTIFIER... it keeps giving me an error when start training, but I think the opposite it correct, moving plans from target to the pre-trained.. I am quiet confused which one is correct?

Thanks