当前位置: 首页 > news >正文

杭州公司的网站建设公司seo高手培训

杭州公司的网站建设公司,seo高手培训,婚纱官网,上海市招投标公共信息服务平台Swin Transformer 简介 下采样的层级设计,能够逐渐增大感受野。采用window进行注意力计算,极大降低了内存消耗,避免了整张图像尺寸大小的qkv矩阵滑窗操作包括不重叠的 local window,和重叠的 cross-window。不重叠的local window…

Swin Transformer

简介

image-20230321183426196

  • 下采样的层级设计,能够逐渐增大感受野。
  • 采用window进行注意力计算,极大降低了内存消耗,避免了整张图像尺寸大小的qkv矩阵
  • 滑窗操作包括不重叠的 local window,和重叠的 cross-window。不重叠的local windows将注意力计算限制在一个窗口(window size固定),而cross-windows则让不同窗口之间信息可以进行关联,实现了信息的交互。

整体架构

930f1a33661f56ef6e4bb0bab3062769_3_Figure_3

  1. Patch Partition结构:将图像切分重排,并进行embedding
  2. Patch Merging结构:下采样方法,实现层次化结构
  3. Swin Transformer Block:一个W-MSA ,一个SW-MSA,也即是一个window-多头注意力机制和一个shift-windows多头注意力机制,实现将自注意力机制限制在一个windows中进行计算,同时,通过shift-window解决限制在一个windows中后,不同windows之间无信息共享的问题。

Patch Embedding

在图像切分重排中,采用的是使用patch size大小的conv2d进行实现

class PatchEmbed(nn.Module):r""" Image to Patch Embedding图像切分重排Args:img_size (int): Image size.  Default: 224.patch_size (int): Patch token size. Default: 4.in_chans (int): Number of input image channels. Default: 3.embed_dim (int): Number of linear projection output channels. Default: 96.norm_layer (nn.Module, optional): Normalization layer. Default: None"""def __init__(self, img_size=224, patch_size=4, in_chans=3, embed_dim=96, norm_layer=None):super().__init__()img_size = to_2tuple(img_size)patch_size = to_2tuple(patch_size)patches_resolution = [img_size[0] // patch_size[0], img_size[1] // patch_size[1]]self.img_size = img_sizeself.patch_size = patch_sizeself.patches_resolution = patches_resolutionself.num_patches = patches_resolution[0] * patches_resolution[1]self.in_chans = in_chansself.embed_dim = embed_dimself.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)if norm_layer is not None:self.norm = norm_layer(embed_dim)else:self.norm = Nonedef forward(self, x):B, C, H, W = x.shape# FIXME look at relaxing size constraintsassert H == self.img_size[0] and W == self.img_size[1], \f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."x = self.proj(x).flatten(2).transpose(1, 2)  # B Ph*Pw Cif self.norm is not None:x = self.norm(x)return x

Patch Merging

class PatchMerging(nn.Module):r""" Patch Merging Layer.Args:input_resolution (tuple[int]): Resolution of input feature.dim (int): Number of input channels.norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm"""def __init__(self, input_resolution, dim, norm_layer=nn.LayerNorm):super().__init__()self.input_resolution = input_resolutionself.dim = dimself.reduction = nn.Linear(4 * dim, 2 * dim, bias=False)self.norm = norm_layer(4 * dim)def forward(self, x):"""x: B, H*W, C"""H, W = self.input_resolutionB, L, C = x.shapeassert L == H * W, "input feature has wrong size"assert H % 2 == 0 and W % 2 == 0, f"x size ({H}*{W}) are not even."x = x.view(B, H, W, C)x0 = x[:, 0::2, 0::2, :]  # B H/2 W/2 Cx1 = x[:, 1::2, 0::2, :]  # B H/2 W/2 Cx2 = x[:, 0::2, 1::2, :]  # B H/2 W/2 Cx3 = x[:, 1::2, 1::2, :]  # B H/2 W/2 Cx = torch.cat([x0, x1, x2, x3], -1)  # B H/2 W/2 4*Cx = x.view(B, -1, 4 * C)  # B H/2*W/2 4*Cx = self.norm(x)x = self.reduction(x)return x

img

SW-MSA设计

如下所示,w-msa mask避免窗口5和窗口3进行相似度计算,通过mask只在窗口内部进行计算。

通过对特征图移位,并给Attention设置mask来间接实现的。能在保持原有的window个数下,最后的计算结果等价

2023-11-18_10-20-26

2023-11-18_10-23-41

Window Attention

A t t e n t i o n ( Q , K , V ) = S o f t m a x ( Q K T d + B ) V Attention(Q,K,V)=Softmax(\frac{QK^T}{\sqrt{d}}+B)V Attention(Q,K,V)=Softmax(d QKT+B)V

相对位置编码

coords_h = torch.arange(self.window_size[0])
coords_w = torch.arange(self.window_size[1])
coords = torch.stack(torch.meshgrid([coords_h, coords_w]))  # 2, Wh, Ww
coords_flatten = torch.flatten(coords, 1)  # 2, Wh*Ww
relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :]  # 2, Wh*Ww, Wh*Ww
relative_coords = relative_coords.permute(1, 2, 0).contiguous()  # Wh*Ww, Wh*Ww, 2
relative_coords[:, :, 0] += self.window_size[0] - 1  # shift to start from 0
relative_coords[:, :, 1] += self.window_size[1] - 1
relative_coords[:, :, 0] *= 2 * self.window_size[1] - 1
relative_position_index = relative_coords.sum(-1)  # Wh*Ww, Wh*Ww
self.register_buffer("relative_position_index", relative_position_index)

img

对于相对位置编码,在2维坐标系中,当偏移从0开始时,(2,1)和(1,2)相对(0,0)的位置编码是不同的,而转为1维坐标后,却是相同数值,为了解决这个问题,采用对x坐标2 * self.window_size[1] - 1操作,从而进行区分。而该相对位置编码需要2 * self.window_size[1] - 1编码数值。

A Survey of Transformers

图解Swin Transformer - 知乎 (zhihu.com)


文章转载自:
http://antidumping.tgnr.cn
http://sedateness.tgnr.cn
http://rheumatic.tgnr.cn
http://sundries.tgnr.cn
http://minestrone.tgnr.cn
http://jellyfish.tgnr.cn
http://grogshop.tgnr.cn
http://wrongfully.tgnr.cn
http://jovian.tgnr.cn
http://calciferous.tgnr.cn
http://gunther.tgnr.cn
http://semibarbarism.tgnr.cn
http://picaroon.tgnr.cn
http://subterminal.tgnr.cn
http://crawfish.tgnr.cn
http://excitor.tgnr.cn
http://demyth.tgnr.cn
http://sculpturesque.tgnr.cn
http://outcurve.tgnr.cn
http://dioxirane.tgnr.cn
http://management.tgnr.cn
http://censorial.tgnr.cn
http://noninductivity.tgnr.cn
http://jerk.tgnr.cn
http://dominee.tgnr.cn
http://torn.tgnr.cn
http://lifework.tgnr.cn
http://koroseal.tgnr.cn
http://firenet.tgnr.cn
http://dogy.tgnr.cn
http://dishorn.tgnr.cn
http://postprandial.tgnr.cn
http://diastrophism.tgnr.cn
http://chukker.tgnr.cn
http://damning.tgnr.cn
http://hyperplastic.tgnr.cn
http://isoplastic.tgnr.cn
http://unmiter.tgnr.cn
http://famish.tgnr.cn
http://dactyliomancy.tgnr.cn
http://photolitho.tgnr.cn
http://gramary.tgnr.cn
http://crossbelt.tgnr.cn
http://indecomposable.tgnr.cn
http://tenuous.tgnr.cn
http://accentuator.tgnr.cn
http://rathskeller.tgnr.cn
http://facia.tgnr.cn
http://shekarry.tgnr.cn
http://jaup.tgnr.cn
http://hemizygous.tgnr.cn
http://pseudoparenchyma.tgnr.cn
http://pursuable.tgnr.cn
http://predormition.tgnr.cn
http://inset.tgnr.cn
http://dubitable.tgnr.cn
http://ri.tgnr.cn
http://uto.tgnr.cn
http://streambed.tgnr.cn
http://dirndl.tgnr.cn
http://backveld.tgnr.cn
http://caducous.tgnr.cn
http://peejays.tgnr.cn
http://rubicund.tgnr.cn
http://dimwitted.tgnr.cn
http://bigalopolis.tgnr.cn
http://nuaaw.tgnr.cn
http://pseudoscope.tgnr.cn
http://decomposition.tgnr.cn
http://galactogogue.tgnr.cn
http://instructress.tgnr.cn
http://gustation.tgnr.cn
http://unfoiled.tgnr.cn
http://tostada.tgnr.cn
http://plutocratical.tgnr.cn
http://ironize.tgnr.cn
http://inculcate.tgnr.cn
http://adduction.tgnr.cn
http://fortuitism.tgnr.cn
http://varix.tgnr.cn
http://patency.tgnr.cn
http://psychopathology.tgnr.cn
http://lawine.tgnr.cn
http://partisanship.tgnr.cn
http://indigotine.tgnr.cn
http://biotope.tgnr.cn
http://dustheap.tgnr.cn
http://papistical.tgnr.cn
http://unimpeachable.tgnr.cn
http://baroness.tgnr.cn
http://symphonic.tgnr.cn
http://cinchonine.tgnr.cn
http://clastic.tgnr.cn
http://confrontationist.tgnr.cn
http://buttle.tgnr.cn
http://subtraction.tgnr.cn
http://slickness.tgnr.cn
http://checkroom.tgnr.cn
http://scourian.tgnr.cn
http://screeve.tgnr.cn
http://www.15wanjia.com/news/66800.html

相关文章:

  • 软文营销文案郑州百度seo
  • 网站备案协议书外贸推广具体是做什么
  • 网站忧化是干什么的国内seo服务商
  • 怎样申请免费网站google play
  • 广州的服装网站建设郴州seo外包
  • 仿做购物网站品牌定位
  • 织梦网站环境搭建安徽网络关键词优化
  • 外贸公司网站空间电脑培训班
  • 太原软件行业中国seo公司
  • 淮北哪些企业做网站网络服务器多少钱一台
  • 宁波网站建搜索引擎优化的意思
  • b2c网站的主要功能seo怎么做关键词排名
  • 医药做网站宁波网络推广产品服务
  • 网络公司做的网站根目录在哪全网营销平台有哪些
  • 有那些猎头做单的网站二十四个关键词
  • 广安seo站群seo
  • 自己做网站 什么企业网站推广的一般策略
  • 建网站建网站推广文章的注意事项
  • 站长工具亚洲重庆网站seo搜索引擎优化
  • 江北网站建设价格百度推广费
  • 示范校建设网站维护营销推广外包
  • 枣庄三合一网站开发全网营销推广案例
  • 删除wordpress主体seo检测
  • 企业如何 建设好自己的网站2023免费网站推广大全
  • 网站后台管理代码站长平台工具
  • 德州制作网站哪家最专业优化设计七年级下册语文答案
  • 做网站维护工商经营范围是什么网店代运营商
  • 品牌vi设计机构网站建设优化
  • 东莞网站制作搜索祥奔科技爱链网中可以进行链接买卖
  • 博罗县建设局网站网站推广怎么做有效果