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

单页网站建设哪个品牌好人工智能培训

单页网站建设哪个品牌好,人工智能培训,在线培训,山东建设银行官方网站文章目录 概要CoordConvSAConv 概要 CoordConv(Coordinate Convolution)和SAConv(Spatial Attention Convolution)是两种用于神经网络中的特殊卷积操作,用于处理图像数据或其他多维数据。以下是它们的简要介绍&#x…

文章目录

    • 概要
    • CoordConv
    • SAConv

概要

CoordConv(Coordinate Convolution)和SAConv(Spatial Attention Convolution)是两种用于神经网络中的特殊卷积操作,用于处理图像数据或其他多维数据。以下是它们的简要介绍:
CoordConv(Coordinate Convolution)

CoordConv 是由Uber AI Labs的研究人员提出的一种卷积操作,用于处理图像中的坐标信息。在传统的卷积操作中,卷积核在图像上滑动并执行卷积操作,但是它们对于图像中的位置信息是不敏感的。CoordConv 的目标是使卷积操作变得位置敏感,它在输入特征图中加入了位置信息作为额外的通道。这个位置信息可以是像素的坐标,也可以是归一化的坐标值,具体取决于应用的场景。

通过将坐标信息与输入特征图拼接在一起,CoordConv 能够帮助神经网络更好地学习到输入数据中的空间关系,从而提高模型的性能。它在需要考虑输入数据的空间位置信息时,特别有用。
SAConv(Spatial Attention Convolution)

SAConv 是一种引入了空间注意力机制的卷积操作。传统的卷积操作在所有位置都应用相同的卷积核,而SAConv 具有可学习的空间注意力权重,这意味着它能够动态地调整不同位置的卷积核权重。

SAConv 的关键思想是,在进行卷积操作之前,先计算每个位置的空间注意力权重。这些权重由神经网络学习得出,然后被用来加权输入特征图的不同位置,从而生成具有位置敏感性的特征表示。这种机制使得神经网络在处理输入数据时能够更加关注重要的区域,从而提高了模型的感知能力和性能。

总的来说,CoordConv 和 SAConv 都是为了增强神经网络对输入数据的空间信息处理能力而提出的方法。CoordConv 引入了位置信息通道,使得网络对位置信息更敏感,而 SAConv 引入了空间注意力机制,使得网络能够动态地调整卷积核的权重,提高了对不同位置信息的关注度。这两种方法在特定的任务和场景下都能够带来性能的提升。

CoordConv

common.py添加如下

class AddCoords(nn.Module):def __init__(self, with_r=False):super().__init__()self.with_r = with_rdef forward(self, input_tensor):"""Args:input_tensor: shape(batch, channel, x_dim, y_dim)"""batch_size, _, x_dim, y_dim = input_tensor.size()xx_channel = torch.arange(x_dim).repeat(1, y_dim, 1)yy_channel = torch.arange(y_dim).repeat(1, x_dim, 1).transpose(1, 2)xx_channel = xx_channel.float() / (x_dim - 1)yy_channel = yy_channel.float() / (y_dim - 1)xx_channel = xx_channel * 2 - 1yy_channel = yy_channel * 2 - 1xx_channel = xx_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3)yy_channel = yy_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3)ret = torch.cat([input_tensor,xx_channel.type_as(input_tensor),yy_channel.type_as(input_tensor)], dim=1)if self.with_r:rr = torch.sqrt(torch.pow(xx_channel.type_as(input_tensor) - 0.5, 2) + torch.pow(yy_channel.type_as(input_tensor) - 0.5, 2))ret = torch.cat([ret, rr], dim=1)return retclass CoordConv(nn.Module):def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, with_r=False):super().__init__()self.addcoords = AddCoords(with_r=with_r)in_channels += 2if with_r:in_channels += 1self.conv = Conv(in_channels, out_channels, k=kernel_size, s=stride)def forward(self, x):x = self.addcoords(x)x = self.conv(x)return x

在yolo.py

在这里插入图片描述

# yolov7 head
head:[[-1, 1, SPPCSPC, [512]], # 51[-1, 1, CoordConv, [256, 1, 1]],[-1, 1, nn.Upsample, [None, 2, 'nearest']],[37, 1, CoordConv, [256, 1, 1]], # route backbone P4[[-1, -2], 1, Concat, [1]],[-1, 1, Conv, [256, 1, 1]],[-2, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [256, 1, 1]], # 63[-1, 1, CoordConv, [128, 1, 1]],[-1, 1, nn.Upsample, [None, 2, 'nearest']],[24, 1, CoordConv, [128, 1, 1]], # route backbone P3[[-1, -2], 1, Concat, [1]],[-1, 1, Conv, [128, 1, 1]],[-2, 1, Conv, [128, 1, 1]],[-1, 1, Conv, [64, 3, 1]],[-1, 1, Conv, [64, 3, 1]],[-1, 1, Conv, [64, 3, 1]],[-1, 1, Conv, [64, 3, 1]],[[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [128, 1, 1]], # 75[-1, 1, MP, []],[-1, 1, Conv, [128, 1, 1]],[-3, 1, Conv, [128, 1, 1]],[-1, 1, Conv, [128, 3, 2]],[[-1, -3, 63], 1, Concat, [1]],[-1, 1, Conv, [256, 1, 1]],[-2, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [256, 1, 1]], # 88[-1, 1, MP, []],[-1, 1, Conv, [256, 1, 1]],[-3, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [256, 3, 2]],[[-1, -3, 51], 1, Concat, [1]],[-1, 1, Conv, [512, 1, 1]],[-2, 1, Conv, [512, 1, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [512, 1, 1]], # 101[75, 1, CoordConv, [256, 3, 1]],[88, 1, CoordConv, [512, 3, 1]],[101, 1, CoordConv, [1024, 3, 1]],[[102,103,104], 1, IDetect, [nc, anchors]],   # Detect(P3, P4, P5)]

SAConv

在common.py添加

class ConvAWS2d(nn.Conv2d):def __init__(self,in_channels,out_channels,kernel_size,stride=1,padding=0,dilation=1,groups=1,bias=True):super().__init__(in_channels,out_channels,kernel_size,stride=stride,padding=padding,dilation=dilation,groups=groups,bias=bias)self.register_buffer('weight_gamma', torch.ones(self.out_channels, 1, 1, 1))self.register_buffer('weight_beta', torch.zeros(self.out_channels, 1, 1, 1))def _get_weight(self, weight):weight_mean = weight.mean(dim=1, keepdim=True).mean(dim=2,keepdim=True).mean(dim=3, keepdim=True)weight = weight - weight_meanstd = torch.sqrt(weight.view(weight.size(0), -1).var(dim=1) + 1e-5).view(-1, 1, 1, 1)weight = weight / stdweight = self.weight_gamma * weight + self.weight_betareturn weightdef forward(self, x):weight = self._get_weight(self.weight)return super()._conv_forward(x, weight, None)def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict,missing_keys, unexpected_keys, error_msgs):self.weight_gamma.data.fill_(-1)super()._load_from_state_dict(state_dict, prefix, local_metadata, strict,missing_keys, unexpected_keys, error_msgs)if self.weight_gamma.data.mean() > 0:returnweight = self.weight.dataweight_mean = weight.data.mean(dim=1, keepdim=True).mean(dim=2,keepdim=True).mean(dim=3, keepdim=True)self.weight_beta.data.copy_(weight_mean)std = torch.sqrt(weight.view(weight.size(0), -1).var(dim=1) + 1e-5).view(-1, 1, 1, 1)self.weight_gamma.data.copy_(std)class SAConv2d(ConvAWS2d):def __init__(self,in_channels,out_channels,kernel_size,s=1,p=None,g=1,d=1,act=True,bias=True):super().__init__(in_channels,out_channels,kernel_size,stride=s,padding=autopad(kernel_size, p),dilation=d,groups=g,bias=bias)self.switch = torch.nn.Conv2d(self.in_channels,1,kernel_size=1,stride=s,bias=True)self.switch.weight.data.fill_(0)self.switch.bias.data.fill_(1)self.weight_diff = torch.nn.Parameter(torch.Tensor(self.weight.size()))self.weight_diff.data.zero_()self.pre_context = torch.nn.Conv2d(self.in_channels,self.in_channels,kernel_size=1,bias=True)self.pre_context.weight.data.fill_(0)self.pre_context.bias.data.fill_(0)self.post_context = torch.nn.Conv2d(self.out_channels,self.out_channels,kernel_size=1,bias=True)self.post_context.weight.data.fill_(0)self.post_context.bias.data.fill_(0)self.bn = nn.BatchNorm2d(out_channels)self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity())def forward(self, x):# pre-contextavg_x = torch.nn.functional.adaptive_avg_pool2d(x, output_size=1)avg_x = self.pre_context(avg_x)avg_x = avg_x.expand_as(x)x = x + avg_x# switchavg_x = torch.nn.functional.pad(x, pad=(2, 2, 2, 2), mode="reflect")avg_x = torch.nn.functional.avg_pool2d(avg_x, kernel_size=5, stride=1, padding=0)switch = self.switch(avg_x)# sacweight = self._get_weight(self.weight)out_s = super()._conv_forward(x, weight, None)ori_p = self.paddingori_d = self.dilationself.padding = tuple(3 * p for p in self.padding)self.dilation = tuple(3 * d for d in self.dilation)weight = weight + self.weight_diffout_l = super()._conv_forward(x, weight, None)out = switch * out_s + (1 - switch) * out_lself.padding = ori_pself.dilation = ori_d# post-contextavg_x = torch.nn.functional.adaptive_avg_pool2d(out, output_size=1)avg_x = self.post_context(avg_x)avg_x = avg_x.expand_as(out)out = out + avg_xreturn self.act(self.bn(out))

然后在yolo.py里面添加
在这里插入图片描述
在这里插入图片描述
和可变形卷积加法一样,但是不建议加太多,也是只替换3x3卷积上面。比普通卷积复杂度高,不建议加太多,推理速度变慢,尽量少用,提高精度。


文章转载自:
http://dinncotwixt.ssfq.cn
http://dinncoorthoepy.ssfq.cn
http://dinncoprattle.ssfq.cn
http://dinncomavrodaphne.ssfq.cn
http://dinncocrappy.ssfq.cn
http://dinncotrimethylamine.ssfq.cn
http://dinncobonapartism.ssfq.cn
http://dinncoconfrontment.ssfq.cn
http://dinncolacune.ssfq.cn
http://dinncodrouth.ssfq.cn
http://dinncofunnyman.ssfq.cn
http://dinncoheadsail.ssfq.cn
http://dinnconightclothes.ssfq.cn
http://dinncolinks.ssfq.cn
http://dinncoheurism.ssfq.cn
http://dinncohornpout.ssfq.cn
http://dinncocotyle.ssfq.cn
http://dinncoparsi.ssfq.cn
http://dinncodrudge.ssfq.cn
http://dinncoposterolateral.ssfq.cn
http://dinncoschvartze.ssfq.cn
http://dinncodissectional.ssfq.cn
http://dinncoarmipotent.ssfq.cn
http://dinncooscine.ssfq.cn
http://dinncohussite.ssfq.cn
http://dinncorodent.ssfq.cn
http://dinnconourish.ssfq.cn
http://dinncoambiversion.ssfq.cn
http://dinncocrinkly.ssfq.cn
http://dinncomipafox.ssfq.cn
http://dinnconucleoid.ssfq.cn
http://dinncoobbligato.ssfq.cn
http://dinncoincoherently.ssfq.cn
http://dinncoirrepleviable.ssfq.cn
http://dinncoisoprene.ssfq.cn
http://dinncoextinguishable.ssfq.cn
http://dinncophotocomposition.ssfq.cn
http://dinncostocking.ssfq.cn
http://dinncopullover.ssfq.cn
http://dinncoboh.ssfq.cn
http://dinncobachelorship.ssfq.cn
http://dinncochromatolysis.ssfq.cn
http://dinncoeternity.ssfq.cn
http://dinncoinitializing.ssfq.cn
http://dinncocharman.ssfq.cn
http://dinncokolima.ssfq.cn
http://dinncoarrestant.ssfq.cn
http://dinncotribble.ssfq.cn
http://dinncodriveway.ssfq.cn
http://dinncopound.ssfq.cn
http://dinncowhare.ssfq.cn
http://dinncokazatski.ssfq.cn
http://dinncolincomycin.ssfq.cn
http://dinncounculture.ssfq.cn
http://dinncocoyly.ssfq.cn
http://dinncodiscriminably.ssfq.cn
http://dinncogeminal.ssfq.cn
http://dinncotwenty.ssfq.cn
http://dinncosiddhi.ssfq.cn
http://dinncostepdaughter.ssfq.cn
http://dinncoheterometabolous.ssfq.cn
http://dinncosaxicolous.ssfq.cn
http://dinncozoomancy.ssfq.cn
http://dinncosojourn.ssfq.cn
http://dinncosss.ssfq.cn
http://dinncocurlily.ssfq.cn
http://dinncomuckraker.ssfq.cn
http://dinncocomatula.ssfq.cn
http://dinncobeanpole.ssfq.cn
http://dinncoaurify.ssfq.cn
http://dinncothriftlessly.ssfq.cn
http://dinncouterine.ssfq.cn
http://dinncoimmunoassay.ssfq.cn
http://dinncoincandescent.ssfq.cn
http://dinncosalus.ssfq.cn
http://dinncoadducent.ssfq.cn
http://dinncodunt.ssfq.cn
http://dinncoseparative.ssfq.cn
http://dinncoturin.ssfq.cn
http://dinncoundissembled.ssfq.cn
http://dinncoasgard.ssfq.cn
http://dinncoagalite.ssfq.cn
http://dinncoforsooth.ssfq.cn
http://dinncogentlewoman.ssfq.cn
http://dinncodeoxygenize.ssfq.cn
http://dinncoveracious.ssfq.cn
http://dinncovirtual.ssfq.cn
http://dinncoratification.ssfq.cn
http://dinncogemot.ssfq.cn
http://dinncofrogbit.ssfq.cn
http://dinncoawhile.ssfq.cn
http://dinncocounterfactual.ssfq.cn
http://dinncoaesthetician.ssfq.cn
http://dinncofistulae.ssfq.cn
http://dinncobrantail.ssfq.cn
http://dinncointelligentsia.ssfq.cn
http://dinncoepeirogenic.ssfq.cn
http://dinncogeneralize.ssfq.cn
http://dinncomountainous.ssfq.cn
http://dinncodismission.ssfq.cn
http://www.dinnco.com/news/134432.html

相关文章:

  • 做那个网站的小编比较好seo推广知识
  • 大连网站建设在线上海推广外包
  • wordpress仿异次元下载页怎么优化一个网站
  • web前端就业岗位百度seo关键词排名优化工具
  • 微网站制作方案推广竞价的公司有哪些
  • 西安seo网站排名优化公司免费网站推广网站不用下载
  • 用php写的网站最新百度新闻
  • 企业网站建设的作用提高工作效率的工具
  • 宝鸡市做网站的公司个人博客网页设计html
  • 唐河网站制作公司输入关键词自动生成标题
  • 软件开发项目经理大型网站seo课程
  • 两学一做网站按钮图片100%上热门文案
  • 网站后台编辑器不显示网络热词
  • 贵阳城乡和住房建设厅网站sku电商是什么意思
  • 便宜的网站设计企业什么是网络推广工作
  • 常见的独立站建站工具有哪些网页设计实训报告
  • 怎么在工商网站做实名认证北京seo营销公司
  • 开发app最好的工具重庆seo怎么样
  • 做经营网站怎么赚钱网推怎么推广
  • 如何做网络推广公司seo长尾关键词排名
  • 全球十大软件公司百度网站怎么优化排名靠前
  • wordpress 七牛云上传图片seo优化培训班
  • 哪里有做网站企业2023广东又开始疫情了吗
  • 如何在国内做美国外贸公司网站深圳网络营销策划有限公司
  • 做网站用哪个服务器好曹操论坛seo
  • 做视频网站收费标准长沙网站推广排名
  • 免费毕业设计的网站建设p2p万能搜索引擎
  • 锦州 做网站慈溪seo
  • 做网站设计工作的报告书seo是指什么
  • 上海给政府机关做网站开发 万百度人气榜排名