RETFound - A foundation model for retinal image

创建虚拟环境:

conda create -n retfound python=3.7.5 -y
conda activate retfound

克隆项目并安装依赖:

git clone <https://github.com/rmaphoh/RETFound_MAE/>
cd RETFound_MAE
pip install -r requirement.txt

README 中提供了两种预训练权重:

彩色眼底图像预训练权重:

https://drive.google.com/file/d/1l62zbWUFTlp214SvK6eMwPQZAzcwoeBE/view?usp=sharing

按照如下结构放置数据集:

├── data folder
    ├── train
        ├── class_a
        ├── class_b
        ├── class_c
    ├── val
        ├── class_a
        ├── class_b
        ├── class_c
    ├── test
        ├── class_a
        ├── class_b
        ├── class_c

github上有公开数据集:

https://github.com/rmaphoh/RETFound_MAE/blob/main/BENCHMARK.md

利用以下代码开始微调:

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 \\
    --input_size 224
  • -batch_size 16:指定批量大小。

  • -epochs 50:训练的轮数为 50。

  • -blr 5e-3:基础学习率为 0.005。

  • -data_path ./IDRiD_data/:你的数据集路径。

  • -finetune ./RETFound_cfp_weights.pth:使用你下载的预训练权重。

如果出现pipebroken报错,尝试将num_workers修改为更小的值,如0,1:

parser.add_argument('--num_workers', default=1, type=int)

超出gpu显存请调小batch_size:

batch_size 8

遇到RuntimeError: CUDA error: device-side assert triggered报错:尝试重新导入数据,保证数据标签不变

遇到 "Argument interpolation should be of type InterpolationMode instead of int. “提醒你将整数类替换成枚举类,可以忽视。