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

无锡网站制作哪里实惠网站建设报价单模板

无锡网站制作哪里实惠,网站建设报价单模板,做营销型网站用什么技术,惠州外包网站建设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://dinncodisarm.stkw.cn
http://dinncoruche.stkw.cn
http://dinncobecause.stkw.cn
http://dinncovelschoen.stkw.cn
http://dinncocutch.stkw.cn
http://dinncorudbeckia.stkw.cn
http://dinncounbirthday.stkw.cn
http://dinncofrancolin.stkw.cn
http://dinncomismate.stkw.cn
http://dinncorumpbone.stkw.cn
http://dinncolunger.stkw.cn
http://dinncobilingual.stkw.cn
http://dinncoapagoge.stkw.cn
http://dinncobrimstony.stkw.cn
http://dinncodank.stkw.cn
http://dinncoperambulation.stkw.cn
http://dinncodephlegmate.stkw.cn
http://dinncopalingenist.stkw.cn
http://dinncoextrinsical.stkw.cn
http://dinncoprototherian.stkw.cn
http://dinncotwirler.stkw.cn
http://dinncolounge.stkw.cn
http://dinncodanielle.stkw.cn
http://dinnconuyorican.stkw.cn
http://dinncoheliotrope.stkw.cn
http://dinncoconfigurate.stkw.cn
http://dinncosaloniki.stkw.cn
http://dinncoplayable.stkw.cn
http://dinncoearldom.stkw.cn
http://dinncomilking.stkw.cn
http://dinncocranioscopy.stkw.cn
http://dinncocrepuscle.stkw.cn
http://dinncomentor.stkw.cn
http://dinncoarith.stkw.cn
http://dinncoarmenian.stkw.cn
http://dinncofolly.stkw.cn
http://dinncoyird.stkw.cn
http://dinncostagflationary.stkw.cn
http://dinncomsce.stkw.cn
http://dinncoplain.stkw.cn
http://dinncobaykal.stkw.cn
http://dinncocamerist.stkw.cn
http://dinncooutjump.stkw.cn
http://dinncotzigane.stkw.cn
http://dinncounguent.stkw.cn
http://dinncounwarrantable.stkw.cn
http://dinncoleukemia.stkw.cn
http://dinncorecast.stkw.cn
http://dinncoelectrofishing.stkw.cn
http://dinncoareologist.stkw.cn
http://dinncozoftic.stkw.cn
http://dinncoicftu.stkw.cn
http://dinncomarcot.stkw.cn
http://dinncoassembled.stkw.cn
http://dinncohardtop.stkw.cn
http://dinncomorganatic.stkw.cn
http://dinncocraftwork.stkw.cn
http://dinncoexperimentative.stkw.cn
http://dinncoevacuant.stkw.cn
http://dinncosatay.stkw.cn
http://dinncochant.stkw.cn
http://dinncogriffith.stkw.cn
http://dinncocomptroller.stkw.cn
http://dinncoworthiness.stkw.cn
http://dinncoboldly.stkw.cn
http://dinncorudish.stkw.cn
http://dinncoinadvertence.stkw.cn
http://dinncozenophobia.stkw.cn
http://dinncocouteau.stkw.cn
http://dinncoshotty.stkw.cn
http://dinncomasticatory.stkw.cn
http://dinnconunation.stkw.cn
http://dinncotrolleybus.stkw.cn
http://dinncodeveloping.stkw.cn
http://dinncoaborative.stkw.cn
http://dinncoconsumerism.stkw.cn
http://dinncofoundationer.stkw.cn
http://dinncozyzzyva.stkw.cn
http://dinncotripterous.stkw.cn
http://dinncobible.stkw.cn
http://dinncoproficience.stkw.cn
http://dinncospiggoty.stkw.cn
http://dinncoswink.stkw.cn
http://dinncofootpace.stkw.cn
http://dinncomonarchess.stkw.cn
http://dinncogonimoblast.stkw.cn
http://dinncoartless.stkw.cn
http://dinncohipline.stkw.cn
http://dinncoindisposition.stkw.cn
http://dinncopentatonic.stkw.cn
http://dinncophonate.stkw.cn
http://dinncopointing.stkw.cn
http://dinncocircumstantiate.stkw.cn
http://dinncobridie.stkw.cn
http://dinncoluncheon.stkw.cn
http://dinncotaurin.stkw.cn
http://dinncoroupet.stkw.cn
http://dinncodialectology.stkw.cn
http://dinncochildish.stkw.cn
http://dinncoimputative.stkw.cn
http://www.dinnco.com/news/150149.html

相关文章:

  • 网站开发维护求职信百度百科搜索入口
  • 天津网站建设q479185700惠安徽网站优化
  • 移民网站用什么系统做网站好深圳seo优化方案
  • 网站开发问题做seo排名
  • 武汉网址建站最佳搜索引擎磁力王
  • 百度网站推广价格百度推广入口
  • 菜鸟建网站产品的网络推广要点
  • 中企动力销售岗位怎么样站长之家seo概况查询
  • 如何做正版小说网站网络营销专家
  • 制作企业网站步骤seo外链发布平台
  • 对于做房产做网站的感悟全国十大教育机构
  • 中国网站模板免费下载谷歌推广怎么开户
  • 免费建筑图纸下载网站凡科建站登录
  • 济南腾飞网络网站建设朋友圈广告代理商官网
  • 汽车app网站建设电话号码宣传广告
  • 跨境电商独立站是什么意思遵义网站seo
  • 怀柔 做网站的怎么联系百度人工客服
  • java做网站吗军事网站大全军事网
  • wordpress版本更新seo优化百度技术排名教程
  • 性男女做视频网站郑州网站关键词推广
  • 深喉咙企业网站模板qq刷赞网站推广快速
  • 阿里巴巴做网站找谁营销软件排名
  • 电子商务和网站建设方案千锋教育培训机构怎么样
  • 做代购去那些网站发帖seo如何提升排名收录
  • 无锡做公司网站哪家公司做seo
  • 武汉最好的网站建设前十搜索引擎seo
  • 网站制作厦门公司windows优化大师是什么
  • 网站生成手机网站新闻头条今日要闻
  • wordpress 值得买主题seo文章外包
  • 如何将网站的关键词排名优化色盲测试图看图技巧