nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

Error occurred when following pretraining_and_finetuning tutorial

Open yy042 opened this issue 1 year ago • 4 comments

Hello. Thank you for your amazing work. I got a problem when I try to fine tune a pretrained model on my personal dataset(Dataset020). Following the steps in documentation/pretraining_and_finetuning.md, I have finished pretraining on Dataset040_KiTS19 successfully. But when I try to run the last order nnUNetv2_train TARGET_DATASET CONFIG FOLD -pretrained_weights PATH_TO_CHECKPOINT, as I run nnUNetv2_train 20 3d_fullres 0 -pretrained_weights D:\nnUNet\nnUNetFrame\nnUNet_results\Dataset040_KiTS19\nnUNetTrainer__custom_plan1__3d_fullres\fold_all\checkpoint_best.pth, an error occured:

File "D:\nnUNet\nnunetv2\run\run_training.py", line 46, in get_trainer_from_args assert issubclass(nnunet_trainer, nnUNetTrainer), 'The requested nnunet trainer class must inherit from '
AssertionError: The requested nnunet trainer class must inherit from nnUNetTrainer

It's odd because I've been strictly follow the instructions in documentation/pretraining_and_finetuning.md, and I have never changed the structure of my nnU-Net. I would appreciate it if you could point out what I have done is wrong. Thank you for your support!

yy042 avatar May 16 '24 16:05 yy042

Hi @yy042 , can you please share all the commands you used when following the pretraining steps?

One thing you could try is setting your checkpoint path in quotation marks like this: nnUNetv2_train TARGET_DATASET CONFIG FOLD -pretrained_weights PATH_TO_CHECKPOINT, as I run nnUNetv2_train 20 3d_fullres 0 -pretrained_weights "D:\nnUNet\nnUNetFrame\nnUNet_results\Dataset040_KiTS19\nnUNetTrainer__custom_plan1__3d_fullres\fold_all\checkpoint_best.pth"

Best, Sebastian

seziegler avatar May 17 '24 14:05 seziegler

Thank you for your reply! I've tried setting checkpoint path in quotation marks, but the same error occurred again. Here are the commands I used when following the pretraining tutorial:

source dataset-Dataset040_KiTS19 target dataset-Dataset020_KidneyTumor

  1. nnUNetv2_plan_and_preprocess -d 20
  2. nnUNetv2_extract_fingerprint -d 40
  3. nnUNetv2_move_plans_between_datasets -s 20 -t 40 -sp nnUNetPlans -tp custom_plan1
  4. nnUNetv2_preprocess -d 40 -plans_name custom_plan1
  5. nnUNetv2_train 40 3d_fullres all -p custom_plan1
  6. nnUNetv2_train 20 3d_fullres 0 -pretrained_weights "D:\nnUNet\nnUNetFrame\nnUNet_results\Dataset040_KiTS19\nnUNetTrainer__custom_plan1__3d_fullres\fold_all\checkpoint_best.pth" -AssertionError: The requested nnunet trainer class must inherit from nnUNetTrainer

yy042 avatar May 17 '24 15:05 yy042

Hi @yy042 ,

can you try running the train command when adding -tr nnUNetTrainer?

seziegler avatar May 21 '24 11:05 seziegler

I had the same error problem. The cause was that the nnUNetTrainer class was loaded from a different module. (In my case, it was due to the custom nnUNetTrainer class being created in a separate file).

This can be confirmed by describing print(f'nnunet_trainer: {nnunet_trainer.__module__}’) print(f'nnUNetTrainer: {nnunetTrainer.__module__}') before the assert issubclass(nnunet_trainer, nnUNetTrainer), The requested nnunet trainer class must inherit from ' \ ' nnUNetTrainer' in run_training.py

U-ma-s avatar Oct 04 '24 04:10 U-ma-s