1.安装
pip install timm
2.timm中有多少个预训练模型
#timm中有多少个预训练模型
model_pretrain_list = timm.list_models(pretrained=True)
print(len(model_pretrain_list), model_pretrain_list[:3])
3加载swin模型一般准会出错
model_ft = timm.create_model('swin_base_patch4_window7_224', pretrained=True, drop_path_rate = 0.2)
报错的内容如下
Downloading: "https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window7_224_22kto1k.pth" to /root/.cache/torch/hub/checkpoints/swin_base_patch4_window7_224_22kto1k.pth
解决办法 去swin官网下载对应的swin_base_patch4_window7_224.pth
(所有模型我都存自己百度网盘了)文件 然后根据提示 重命名为swin_base_patch4_window7_224_22kto1k.pth
再将该文件移动到/root/.cache/torch/hub/checkpoints/
该目录下
这样timm就可以爽歪歪的用了
4下载预训练模型的官网
- 官网:https://github.com/microsoft/Swin-Transformer 官网提供了百度云的下载连接
timm中可用的swin模型
```python
#可用的swin模型
swin_transformer = ['swin_base_patch4_window7_224',
'swin_base_patch4_window7_224_in22k',
'swin_base_patch4_window12_384',
'swin_base_patch4_window12_384_in22k',
'swin_large_patch4_window7_224',
'swin_large_patch4_window7_224_in22k',
'swin_large_patch4_window12_384',
'swin_large_patch4_window12_384_in22k',
'swin_s3_base_224',
'swin_s3_small_224',
'swin_s3_tiny_224',
'swin_small_patch4_window7_224',
'swin_tiny_patch4_window7_224',
'swinv2_base_window8_256',
'swinv2_base_window12_192_22k',
'swinv2_base_window12to16_192to256_22kft1k',
'swinv2_base_window12to24_192to384_22kft1k',
'swinv2_base_window16_256',
'swinv2_cr_small_224',
'swinv2_cr_small_ns_224',
'swinv2_cr_tiny_ns_224',
'swinv2_large_window12_192_22k',
'swinv2_large_window12to16_192to256_22kft1k',
'swinv2_large_window12to24_192to384_22kft1k',
'swinv2_small_window8_256',
'swinv2_small_window16_256',
'swinv2_tiny_window8_256',
'swinv2_tiny_window16_256',]
#可用的VIT模型
vision_tranformer = ['visformer_small',
'vit_base_patch8_224',
'vit_base_patch8_224_dino',
'vit_base_patch8_224_in21k',
'vit_base_patch16_224',
'vit_base_patch16_224_dino',
'vit_base_patch16_224_in21k',
'vit_base_patch16_224_miil',
'vit_base_patch16_224_miil_in21k',
'vit_base_patch16_224_sam',
'vit_base_patch16_384',
'vit_base_patch16_rpn_224',
'vit_base_patch32_224',
'vit_base_patch32_224_clip_laion2b',
'vit_base_patch32_224_in21k',
'vit_base_patch32_224_sam',
'vit_base_patch32_384',
'vit_base_r50_s16_224_in21k',
'vit_base_r50_s16_384',
'vit_giant_patch14_224_clip_laion2b',
'vit_huge_patch14_224_clip_laion2b',
'vit_huge_patch14_224_in21k',
'vit_large_patch14_224_clip_laion2b',
'vit_large_patch16_224',
'vit_large_patch16_224_in21k',
'vit_large_patch16_384',
'vit_large_patch32_224_in21k',
'vit_large_patch32_384',
'vit_large_r50_s32_224',
'vit_large_r50_s32_224_in21k',
'vit_large_r50_s32_384',
'vit_relpos_base_patch16_224',
'vit_relpos_base_patch16_clsgap_224',
'vit_relpos_base_patch32_plus_rpn_256',
'vit_relpos_medium_patch16_224',
'vit_relpos_medium_patch16_cls_224',
'vit_relpos_medium_patch16_rpn_224',
'vit_relpos_small_patch16_224',
'vit_small_patch8_224_dino',
'vit_small_patch16_224',
'vit_small_patch16_224_dino',
'vit_small_patch16_224_in21k',
'vit_small_patch16_384',
'vit_small_patch32_224',
'vit_small_patch32_224_in21k',
'vit_small_patch32_384',
'vit_small_r26_s32_224',
'vit_small_r26_s32_224_in21k',
'vit_small_r26_s32_384',
'vit_srelpos_medium_patch16_224',
'vit_srelpos_small_patch16_224',
'vit_tiny_patch16_224',
'vit_tiny_patch16_224_in21k',
'vit_tiny_patch16_384',
'vit_tiny_r_s16_p8_224',
'vit_tiny_r_s16_p8_224_in21k',
'vit_tiny_r_s16_p8_384',]