Swin-Transformer 源码学习与使用手册

发布时间 2023-09-06 22:16:02作者: spx88

拜读了VIT以及TNT以及Swin-Transformer 的论文,结合B站up主的分析,

预感Swin-Transformer具有ResNet似的跨里程碑式的意义,

因此学习Swin-Transformer源码及其使用,记录如下。


 

 

Run 

Swin-T
python -m torch.distributed.launch --nproc_per_node 2 --master_port 12345 main.py --cfg configs/swin/swin_tiny_patch4_window7_224.yaml --data-path data --batch-size 128

Swin-S
python -m torch.distributed.launch --nproc_per_node 2 --master_port 12345 main.py --cfg configs/swin/swin_small_patch4_window7_224.yaml --data-path data --batch-size 128

Swin-B
python -m torch.distributed.launch --nproc_per_node 2 --master_port 12345 main.py --cfg configs/swin/swin_base_patch4_window7_224.yaml --data-path data --batch-size 64 --accumulation-steps 2

上述命令中,
--nproc_per_node 为指定gpu数量,
--master_port 为指定端口号
--cfg 为指定配置yaml文件,该文件中参数较为重要,如下图所示

 --data_path 为数据集路径,需要将数据集命名为 train 和 val

--batch_size 为批次大小


 

config.py

 

_C.MODEL.RESUME 该参数比较重要,为预训练模型的路径
_C.MODEL.NUM_CLASSES 为分类类别数