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 官网提供了百度云的下载连接
-
hrnet https://github.com/HRNet/HRNet-Image-Classification
文章来源:https://www.toymoban.com/news/detail-575797.html
注意convnext
- connext输出与分类层的输入 一定要一样
文章来源地址https://www.toymoban.com/news/detail-575797.html
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',]`
参考文章
[vison transformer](https://zhuanlan.zhihu.com/p/350837279)
[swin](https://zhuanlan.zhihu.com/p/485716110#:~:text=Swin%20Transformer%20%E6%98%AF%E5%9C%A8%20Vision%20Transformer%20%E7%9A%84%E5%9F%BA%E7%A1%80%E4%B8%8A%E4%BD%BF%E7%94%A8%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%EF%BC%88shifted,windows,%20SW%EF%BC%89%E8%BF%9B%E8%A1%8C%E6%94%B9%E9%80%A0%E8%80%8C%E6%9D%A5%E3%80%82%20%E5%AE%83%E5%B0%86%20Vision%20Transformer%20%E4%B8%AD%E5%9B%BA%E5%AE%9A%E5%A4%A7%E5%B0%8F%E7%9A%84%E9%87%87%E6%A0%B7%E5%BF%AB%E6%8C%89%E7%85%A7%E5%B1%82%E6%AC%A1%E5%88%86%E6%88%90%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E7%9A%84%E5%9D%97%EF%BC%88Windows%EF%BC%89%EF%BC%8C%E6%AF%8F%E4%B8%80%E4%B8%AA%E5%9D%97%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BF%A1%E6%81%AF%E5%B9%B6%E4%B8%8D%E5%85%B1%E9%80%9A%E3%80%81%E7%8B%AC%E7%AB%8B%E8%BF%90%E7%AE%97%E4%BB%8E%E8%80%8C%E5%A4%A7%E5%A4%A7%E6%8F%90%E9%AB%98%E4%BA%86%E8%AE%A1%E7%AE%97%E6%95%88%E7%8E%87%E3%80%82)
到了这里,关于timm使用swin-transformer的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!