Views
No views yet
conda create -n retfound python=3.7.5 -y
conda activate retfoundgit clone https://github.com/rmaphoh/RETFound_MAE/
cd RETFound_MAE
pip install -r requirement.txt
python -m torch.distributed.launch --nproc_per_node=1 --master_port=48798 main_finetune.py \
--batch_size 16 \
--world_size 1 \
--model vit_large_patch16 \
--epochs 50 \
--blr 5e-3 --layer_decay 0.65 \
--weight_decay 0.05 --drop_path 0.2 \
--nb_classes 5 \
--data_path ./IDRiD_data/ \
--task ./finetune_IDRiD/ \
--finetune ./RETFound_cfp_weights.pth
python -m torch.distributed.launch --nproc_per_node=1 --master_port=48798 main_finetune.py \
--eval --batch_size 16 \
--world_size 1 \
--model vit_large_patch16 \
--epochs 50 \
--blr 5e-3 --layer_decay 0.65 \
--weight_decay 0.05 --drop_path 0.2 \
--nb_classes 5 \
--data_path ./IDRiD_data/ \
--task ./internal_IDRiD/ \
--resume ./finetune_IDRiD/checkpoint-best.pth
1import torch
2import models_vit
3from util.pos_embed import interpolate_pos_embed
4from timm.models.layers import trunc_normal_
5
6# call the model
7model = models_vit.__dict__['vit_large_patch16'](
8 num_classes=2,
9 drop_path_rate=0.2,
10 global_pool=True,
11)
12
13# load RETFound weights
14checkpoint = torch.load('RETFound_cfp_weights.pth', map_location='cpu')
15checkpoint_model = checkpoint['model']
16state_dict = model.state_dict()
17for k in ['head.weight', 'head.bias']:
18 if k in checkpoint_model and checkpoint_model[k].shape != state_dict[k].shape:
19 print(f"Removing key {k} from pretrained checkpoint")
20 del checkpoint_model[k]
21
22# interpolate position embedding
23interpolate_pos_embed(model, checkpoint_model)
24
25# load pre-trained model
26msg = model.load_state_dict(checkpoint_model, strict=False)
27
28assert set(msg.missing_keys) == {'head.weight', 'head.bias', 'fc_norm.weight', 'fc_norm.bias'}
29
30# manually initialize fc layer
31trunc_normal_(model.head.weight, std=2e-5)
32
33print("Model = %s" % str(model))