当前位置:网站首页>搭建Vision Transformer系列实践,终于见面了,Timm库!
搭建Vision Transformer系列实践,终于见面了,Timm库!
2022-07-25 11:29:00 【MengYa_Dream】
前言:工具用不好,万事都烦恼,原本真的就是很简单的一个思路实现,偏偏绕了一圈又一圈,今天就来认识认识Timm库吧!
目录
4.2 Timm库的Vision Transformer活用
4.2.1 vision_transformer.py参数解读
4.2.2 Timm库的调用搭建Vision Transformer
目前,pytorch的知名度就不用说了,vision transformer的知名度,懂的都懂。其实,自己搭建vision transformer原本就是我的初衷,奈何资料根本就是无从下手,主要就是活用问题。今天,突然发现,也没想有想象中那么糟糕,从前人的实验中,还是由迹可寻的。
先放初步学习时候看的一些手把手搭建transformer框架理念和实践的资源:
1.百度飞桨提供的-从零开始学视觉Transformer
理论还是比较详细的,代码实践则是构建在百度子的paddle库上,与pytorch有所区别,但本意还是不变的。
Paddle-Pytorch API对应表:paddle pytorch 对照
2.资源:视觉Transformer优秀的开源工作
视觉 Transformer 优秀开源工作:timm 库 vision transformer 代码解读
python timm库-CSDN博客_python timm
3.如何发现的Timm-Debug
一直在尝试搭建自己的网络模型,却迟迟没有得到自己想要的效果,其实,挺痛苦的。究其原因还是复现前人的工作,复现了很多,但往往也没有深入解读,因为浮在表面,怎么可能去知晓他的真实意图呢?怎么知道他是怎么引用前人的经验呢?就开始了一遍又一遍的Debug,一个点一个点的突破学习,介于空降python的我,很多知识也开始积累起来了,果然,只要思想不滑坡,办法总比困难多!
本次就是科普timm库啦!这是我复现Debug所观察到作者进行Vision Transformer模块时,所进行的操作,根本就不是完全自己搭建哇!有现成的工具,加以整改就好!一切好像又变的美好了起来哈哈哈哈!
4 Timm库
4.1 概念
Timm:pyTorImageModels,简单来说,就是PyTorch的库之一,也算是torchvision.models的扩展模块,面向CV的模型,主要以分类为主。同时,所有的模型都有默认的API。
模型介绍:Model Summaries - Pytorch Image Models (rwightman.github.io)
模型结果:Results - Pytorch Image Models (rwightman.github.io)
4.2 Timm库的Vision Transformer活用
4.2.1 vision_transformer.py参数解读
- img_size: 图像大小,默认224,tuple类型,内部int类型。
- patch_size: Patch size,默认16,tuple类型,内部int类型。
- in_chans: 输入图像的channel数,默认3,int类型。
- num_classes: classification head的分类数,默认1000,int类型。
- embed_dim:Transformer的embedding dimension,默认768, int类型。
- depth: Transformer的Block的数量,默认12,int类型。
- num_head: attention heads的数量,默认12,int类型。
- mlp_ratio: mlp hidden dim/embedding dim的值,默认4, int类型。
- qkv_bias: attention模块计算qkv时,需要bias吗?默认True,bool类型。
- qk_scale: 通常为None。
- drop_rate: dropout rate,默认0,float类型。
- attn_drop_rate: attention模块的dropout rate,默认0,float类型。
- drop_path_rate: 默认0,float类型。
- hybrid_backbone: 在把图像转换成Patch之前,需要先通过一个Backbone吗?默认None。如果是None,就直接把图像转化成Patch。如果不是None,就先通过这个Backbone,再转化成Patch,nn.Module类型。
- norm_layer: 归一化层类型,默认None,nn.Module类型。
- 元组(Tulpe)是Python中另外的一种数据类型,和列表(List)一样也是一组有序对象的集合。
4.2.2 Timm库的调用搭建Vision Transformer
(1)导入必要的库和模型:
import timm(2)调用timm库中的模型:
model = timm.create_model("vit_deit_base_patch16_384", pretrained=pretrained)(3)按需调整,有需求的话,后续整理
边栏推荐
- PHP 上传ftp路径文件到外网服务器上 curl base64图片
- Meta learning (meta learning and small sample learning)
- R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、使用step函数构建前向逐步回归模型筛选预测变量的最佳子集、scope参数指定候选预测变量
- The bank's wealth management subsidiary accumulates power to distribute a shares; The rectification of cash management financial products was accelerated
- 【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
- Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor
- After having a meal with trump, I wrote this article
- 【微服务~Sentinel】Sentinel降级、限流、熔断
- flink sql client 连接mysql报错异常,如何解决?
- Client open download, welcome to try
猜你喜欢
![[multimodal] hit: hierarchical transformer with momentum contract for video text retrieval iccv 2021](/img/48/d5ec2b80cd949b359bcb0bcf08f4eb.png)
[multimodal] hit: hierarchical transformer with momentum contract for video text retrieval iccv 2021

Application of comparative learning (lcgnn, videomoco, graphcl, XMC GaN)

'C:\xampp\php\ext\php_zip.dll' - %1 不是有效的 Win32 应用程序 解决

OSPF comprehensive experiment

Learning to Pre-train Graph Neural Networks(图预训练与微调差异)

GPT plus money (OpenAI CLIP,DALL-E)

【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020

PHP curl post length required error setting header header

php curl post Length Required 错误设置header头
![[multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22](/img/02/5f24b4af44f2f9933ce0f031d69a19.png)
[multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22
随机推荐
R语言使用wilcox.test函数执行wilcox符号秩检验获取总体中位数(median)的置信区间(默认输出结果包括95%置信水平的置信区间)
记录一次线上死锁的定位分析
'C:\xampp\php\ext\php_ zip. Dll'-%1 is not a valid Win32 Application Solution
Go garbage collector Guide
【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021
Solutions to the failure of winddowns planning task execution bat to execute PHP files
给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
异构图神经网络用于推荐系统问题(ACKRec,HFGN)
[RS sampling] a gain tuning dynamic negative sampler for recommendation (WWW 2022)
Video Caption(跨模态视频摘要/字幕生成)
NLP的基本概念1
【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)
'C:\xampp\php\ext\php_zip.dll' - %1 不是有效的 Win32 应用程序 解决
flink sql client 连接mysql报错异常,如何解决?
Zero-Shot Image Retrieval(零样本跨模态检索)
I advise those students who have just joined the work: if you want to enter the big factory, you must master these concurrent programming knowledge! Complete learning route!! (recommended Collection)
马斯克的“灵魂永生”:一半炒作,一半忽悠
【微服务~Sentinel】Sentinel降级、限流、熔断
PHP curl post length required error setting header header