Dite-HRNet: Dynamic Lightweight High-Resolution Network for Human PoseEstimation

本文主要是介绍Dite-HRNet: Dynamic Lightweight High-Resolution Network for Human PoseEstimation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

阅读此篇文章的感触:

首先针对ACM提出两种类型:DCM和GCM

1. 首先介绍ACM的组成:

① 提出------adaptive context pooling, 包括一个1*1操作和softmax,以及transpose操作

②context shifting, 就是将context pooling特征图谱经过两个 1 × 1 convolutions with non-linear activation(1*1+BN+ReLu+1*1+BN+ReLu)和sigmoid函数

③ 将求得的shift通道权重与输入特征图谱进行像素相乘。

以上就是ACM的答题过程,针对DCM和GCM两种模块ACM的第一个步骤是不一样的。

2.DCM 的介绍

首先它是针对不同分支的不同分辨率进行聚合的,因此在ACM的第一步adaptive context pooling会有所不同。DCM的操作过程是将所有输入尺寸除以最小分辨率的尺寸,即H\times W/(H_{min}\times W_{min}),然后在合并(concat)

具体代码如下

class DenseContextModeling(nn.Module):def __init__(self, channels, reduction):super().__init__()num_branches = len(channels)self.reduction = reduction[num_branches-2]self.channels = channelstotal_channel = sum(channels)mid_channels = total_channel // self.reduction##这个是ACM中的adaptive context pooling, a context mask,一个1*1卷积和softmax部分 self.conv_mask = nn.ModuleList([nn.Conv2d(channels[i], 1, kernel_size=1, stride=1, padding=0, bias=True)for i in range(len(channels))])self.softmax = nn.Softmax(dim=2)##这个是shift操作——2个1*1卷积和一个sigmoid函数self.channel_attention = nn.Sequential(nn.Conv2d(total_channel, mid_channels, kernel_size=1, stride=1, padding=0, bias=False),nn.BatchNorm2d(mid_channels),nn.ReLU(inplace=True),nn.Conv2d(mid_channels, total_channel, kernel_size=1, stride=1, padding=0, bias=True),nn.Sigmoid())##这个就是真正的ACM实现def global_spatial_pool(self, x, mini_size, i):batch, channel, height, width = x.size()mini_height, mini_width = mini_size# [N, C, H, W]x_m = x# [N, C, H * W]x_m = x_m.view(batch, channel, height * width)# [N, MH * MW, C, (H * W) / (MH * MW)]x_m = x_m.view(batch, mini_height * mini_width, channel, (height * width) // (mini_height * mini_width))# [N, 1, H, W]mask = self.conv_mask[i](x)# [N, 1, H * W]mask = mask.view(batch, 1, height * width)# [N, 1, H * W]mask = self.softmax(mask)# [N, MH * MW, (H * W) / (MH * MW)]mask = mask.view(batch, mini_height * mini_width, (height * width) // (mini_height * mini_width))# [N, MH * MW, (H * W) / (MH * MW), 1]mask = mask.unsqueeze(-1)# [N, MH * MW, C, 1]x = torch.matmul(x_m, mask)# [N, C, MH * MW, 1]x = x.permute(0, 2, 1, 3)# [N, C, MH, MW]x = x.view(batch, channel, mini_height, mini_width)return xdef forward(self, x):mini_size = x[-1].size()[-2:]out = [self.global_spatial_pool(s, mini_size, i) for s, i in zip(x[:-1], range(len(x)))] + [x[-1]]out = torch.cat(out, dim=1)out = self.channel_attention(out)out = torch.split(out, self.channels, dim=1)out = [s * F.interpolate(a, size=s.size()[-2:], mode='nearest') for s, a in zip(x, out)]return out

2.GCM 

代码

class GlobalContextModeling(nn.Module):def __init__(self, channels, num_branch, reduction, with_cp=False):super().__init__()self.with_cp = with_cpself.reduction = reduction[num_branch]mid_channels = channels // self.reductionself.conv_mask = nn.Conv2d(channels, 1, kernel_size=1, stride=1, padding=0, bias=True)self.softmax = nn.Softmax(dim=2)self.channel_attention = nn.Sequential(nn.Conv2d(channels, mid_channels, kernel_size=1, stride=1, padding=0, bias=False),nn.BatchNorm2d(mid_channels),nn.ReLU(inplace=True),nn.Conv2d(mid_channels, channels, kernel_size=1, stride=1, padding=0, bias=True),nn.Sigmoid())self.bn = nn.BatchNorm2d(channels)def global_spatial_pool(self, x):batch, channel, height, width = x.size()# [N, C, H, W]x_m = x# [N, C, H * W]x_m = x_m.view(batch, channel, height * width)# [N, 1, C, H * W]x_m = x_m.unsqueeze(1)# [N, 1, H, W]mask = self.conv_mask(x)# [N, 1, H * W]mask = mask.view(batch, 1, height * width)# [N, 1, H * W]mask = self.softmax(mask)# [N, 1, H * W, 1]mask = mask.unsqueeze(-1)# [N, 1, C, 1]x = torch.matmul(x_m, mask)# [N, C, 1, 1]x = x.permute(0, 2, 1, 3)return xdef forward(self, x):def _inner_forward(x):identity = xx = self.global_spatial_pool(x)x = self.channel_attention(x)x = self.bn(identity * x)return xif self.with_cp and x.requires_grad:x = cp.checkpoint(_inner_forward, x)else:x = _inner_forward(x)return x

DSC代码

class DynamicSplitConvolution(nn.Module):def __init__(self, channels, stride, num_branch, num_groups, num_kernels, with_cp=False):super().__init__()self.with_cp = with_cpself.num_groups = num_groups[num_branch]self.num_kernels = num_kernels[num_branch]self.split_channels = _split_channels(channels, self.num_groups)self.conv = nn.ModuleList([ConvBN(self.split_channels[i],self.split_channels[i],kernel_size=i * 2 + 3,stride=stride,padding=i + 1,groups=self.split_channels[i],num_kernels=self.num_kernels)for i in range(self.num_groups)])def forward(self, x):def _inner_forward(x):if self.num_groups == 1:x = self.conv[0](x)else:x_split = torch.split(x, self.split_channels, dim=1)x = [conv(t) for conv, t in zip(self.conv, x_split)]x = torch.cat(x, dim=1)x = channel_shuffle(x, self.num_groups)return xif self.with_cp and x.requires_grad:x = cp.checkpoint(_inner_forward, x)else:x = _inner_forward(x)return x

在这里所有的卷积和采用的是动态卷积生成卷积核

动态卷积采用的是每一个输入特征图谱都有K个不同的卷积核(卷积核的大小一样,不一样的是参数值),如何生成K个不同的卷积核,采用pytorch里面的F.conv2函数自己定义。首先是生成batchsize个K个卷积核,采用的是SENet函数。然后是对F.conv2函数进行研究发现维度和现有想法不一致,如何实现每一个输入尺寸特征图谱有K个不同卷积核参数,现将输入维度变成batchsize*inplane,然后group=batchsize,这样,每一个分支代表一个特征图谱上的输入channel个数,且每一个特征图谱具有K个不同卷积核参数。

class KernelAttention(nn.Module):def __init__(self, channels, reduction=4, num_kernels=4, init_weight=True):super().__init__()if channels != 3:mid_channels = channels // reductionelse:mid_channels = num_kernelsself.avg_pool = nn.AdaptiveAvgPool2d(1)self.conv1 = nn.Conv2d(channels, mid_channels, kernel_size=1, bias=False)self.bn = nn.BatchNorm2d(mid_channels)self.relu = nn.ReLU(inplace=True)self.conv2 = nn.Conv2d(mid_channels, num_kernels, kernel_size=1, bias=True)self.sigmoid = nn.Sigmoid()if init_weight:self._initialize_weights()def _initialize_weights(self):for m in self.modules():if isinstance(m, nn.Conv2d):nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')if m.bias is not None:nn.init.constant_(m.bias, 0)if isinstance(m, nn.BatchNorm2d):nn.init.constant_(m.weight, 1)nn.init.constant_(m.bias, 0)def forward(self, x):x = self.avg_pool(x)x = self.conv1(x)x = self.bn(x)x = self.relu(x)x = self.conv2(x).view(x.shape[0], -1)x = self.sigmoid(x)return xclass KernelAggregation(nn.Module):def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, num_kernels,init_weight=True):super().__init__()self.in_channels = in_channelsself.out_channels = out_channelsself.kernel_size = kernel_sizeself.stride = strideself.padding = paddingself.dilation = dilationself.groups = groupsself.bias = biasself.num_kernels = num_kernelsself.weight = nn.Parameter(torch.randn(num_kernels, out_channels, in_channels // groups, kernel_size, kernel_size),requires_grad=True)if bias:self.bias = nn.Parameter(torch.zeros(num_kernels, out_channels))else:self.bias = Noneif init_weight:self._initialize_weights()def _initialize_weights(self):for i in range(self.num_kernels):nn.init.kaiming_uniform_(self.weight[i])def forward(self, x, attention):batch_size, in_channels, height, width = x.size()x = x.contiguous().view(1, batch_size * self.in_channels, height, width)weight = self.weight.contiguous().view(self.num_kernels, -1)weight = torch.mm(attention, weight).contiguous().view(batch_size * self.out_channels,self.in_channels // self.groups,self.kernel_size,self.kernel_size)if self.bias is not None:bias = torch.mm(attention, self.bias).contiguous().view(-1)x = F.conv2d(x,weight=weight,bias=bias,stride=self.stride,padding=self.padding,dilation=self.dilation,groups=self.groups * batch_size)else:x = F.conv2d(x,weight=weight,bias=None,stride=self.stride,padding=self.padding,dilation=self.dilation,groups=self.groups * batch_size)x = x.contiguous().view(batch_size, self.out_channels, x.shape[-2], x.shape[-1])return xclass DynamicKernelAggregation(nn.Module):def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True,num_kernels=4):super().__init__()assert in_channels % groups == 0self.attention = KernelAttention(in_channels,num_kernels=num_kernels)self.aggregation = KernelAggregation(in_channels,out_channels,kernel_size=kernel_size,stride=stride,padding=padding,dilation=dilation,groups=groups,bias=bias,num_kernels=num_kernels)def forward(self, x):attention = xattention = self.attention(attention)x = self.aggregation(x, attention)return x

Enable GingerCannot connect to Ginger Check your internet connection
or reload the browserDisable in this text fieldRephraseRephrase current sentence7Log in to edit with Ginger×

这篇关于Dite-HRNet: Dynamic Lightweight High-Resolution Network for Human PoseEstimation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/547133

相关文章

BookSim2 安装步骤教程 Network-on-Chips (NoCs) 片上网络模拟器 含视频

BookSim简介 BookSim2 一个用于Network-on-Chips (NoCs) 芯片上网络的周期精确模拟器。该模拟器的设计是为了实现网络组件的模拟灵活性和精确建模。  BookSim1 是一个通用的网络模拟器,并不专门针对片上环境。不支持在片上网络环境中提出的一些更先进的功能和拓扑结构。 背景 随着集成在单个芯片上的核心和模块数量的不断增加,片上网络正成为现代微处理器不可或缺

论文《Tree Decomposed Graph Neural Network》笔记

【TDGNN】本文提出了一种树分解方法来解决不同层邻域之间的特征平滑问题,增加了网络层配置的灵活性。通过图扩散过程表征了多跳依赖性(multi-hop dependency),构建了TDGNN模型,该模型可以灵活地结合大感受场的信息,并利用多跳依赖性进行信息聚合。 本文发表在2021年CIKM会议上,作者学校:Vanderbilt University,引用量:59。 CIKM会议简介:全称C

强制类型转换static_cast、dynamic_cast、reinterpret_cast、和const_cast

C++类型转换分为:隐式类型转换和显式类型转换 第1部分. 隐式类型转换 又称为“标准转换”,包括以下几种情况: 1) 算术转换(Arithmetic conversion) : 在混合类型的 算术表达式中, 最宽的数据类型成为目标转换类型。   int  ival  =   3 ; double  dval  =   3.14159 ; ival  +

Representation Learning on Network 网络表示学习笔记

Embedding Nodes Encoder-decoder ViewEncoding Methods 1 Factorization based2 Random Walk based3 Deep Learning based 网络表示学习(Representation Learning on Network),一般说的就是向量化(Embedding)技术,简单来说,就是

聊聊 C# dynamic 类型,并分享一个将 dynamic 类型变量转为其它类型的技巧和实例

前言 dynamic 是一种有别于传统变量类型的动态类型声明,刚开始接触可能在理解上会有些困难,可以简单地把它理解为一个盲盒,你可以任意猜测盒子有什么东西,并认为这些东西真正存在而进行处理,等到真正打开时,才能真正确定这些东西是不是真的存在。 所以,当使用 dynamic 声明一个变量时,编译器不会去检查该变量的成员或方法的有效性,换句话说,你可以调用任意成员或方法,即使它们不存在,编译器

AIGC-CVPR2024best paper-Rich Human Feedback for Text-to-Image Generation-论文精读

Rich Human Feedback for Text-to-Image Generation斩获CVPR2024最佳论文!受大模型中的RLHF技术启发,团队用人类反馈来改进Stable Diffusion等文生图模型。这项研究来自UCSD、谷歌等。 在本文中,作者通过标记不可信或与文本不对齐的图像区域,以及注释文本提示中的哪些单词在图像上被歪曲或丢失来丰富反馈信号。 在 18K 生成图像 (R

chrome浏览器 network 显示感叹号(chrome network thinttling is enabled)

chrome浏览器上network出现一个黄色感叹号,鼠标移上去提示chrome network thinttling is enabled,这是因为开启了节流模式,直接把网络模式改为no throttling(有的浏览器为online)就可以了。 ##Tips: 1、no throttling/online:正常的网络 2、Fast3G:比较快的3g网络(比正常的慢) 3、Slow3G:比较

[Uva 11990] Dynamic Inversion (CDQ分治入门)

Uva - 11990 动态逆序对,求删除一个点之前序列中逆序对的个数 首先倒过来看这个问题,把点先全部删掉 然后从最后一个点开始倒着往数列中加点 求加完这个点逆序对的变化 CDQ分治做法 把删除时间看作 t,下标看作 x,值看作 y 然后对 x排序,对 t偏序,用树状数组维护 y 具体来说就是对于每个点 (t0,x0,y0) (t_0, x_0, y_0) 先统计

模型压缩:Networks Slimming-Learning Efficient Convolutional Networks through Network Slimming

Network Slimming-Learning Efficient Convolutional Networks through Network Slimming(Paper) 2017年ICCV的一篇paper,思路清晰,骨骼清奇~~ 创新点: 1. 利用batch normalization中的缩放因子γ 作为重要性因子,即γ越小,所对应的channel不太重要,就可以裁剪(prun

eclipse 如何创建一个Dynamic Web project (动态web项目)

1.准备工作: eclipse的下载安装 2.创建Dynamic Web project 至此一个Dynamic web project生成完毕。 项目结构为: