论文地址:
官方源码:
HRNet网络结构
这里引用“太阳花的小绿豆”绘制的一张基于HRNet-32模型的结构图 。便于后续理解 。
重要的部分写在代码注释里了,阅读的时候注意 。
代码详解 函数
def get_pose_net(cfg, is_train, **kwargs):model = PoseHighResolutionNet(cfg, **kwargs)if is_train and cfg['MODEL']['INIT_WEIGHTS']:model.init_weights(cfg['MODEL']['PRETRAINED'])return model
使用了t类,让我们进入到这个类看一下 。
【HRNet网络代码解读:Deep High】首先看函数:
def forward(self, x):x = self.conv1(x)x = self.bn1(x)x = self.relu(x)x = self.conv2(x)x = self.bn2(x)x = self.relu(x)x = self.layer1(x)
所对应的stem net为:
# stem netself.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=2, padding=1,bias=False)self.bn1 = nn.BatchNorm2d(64, momentum=BN_MOMENTUM)self.conv2 = nn.Conv2d(64, 64, kernel_size=3, stride=2, padding=1,bias=False)self.bn2 = nn.BatchNorm2d(64, momentum=BN_MOMENTUM)self.relu = nn.ReLU(inplace=True)self.layer1 = self._make_layer(Bottleneck, 64, 4)
这里经过两个卷积bn激活函数的操作,后接一个模块,特征通道数下采样4倍,通道变为256.
其中由(, 64, 4)构建 。
函数
让我们看下的具体操作 。
def _make_layer(self, block, planes, blocks, stride=1):downsample = Noneif stride != 1 or self.inplanes != planes * block.expansion:downsample = nn.Sequential(nn.Conv2d(self.inplanes, planes * block.expansion,kernel_size=1, stride=stride, bias=False),nn.BatchNorm2d(planes * block.expansion, momentum=BN_MOMENTUM),)layers = []layers.append(block(self.inplanes, planes, stride, downsample))# 通道数由64变为256self.inplanes = planes * block.expansion# self.inplanes = 64 * 4 = 256for i in range(1, blocks):# 重复堆叠三次,不使用downsample,其实这里的downsample操作也并没有进行下采样 。# 输入通道数为256,输出通道数也为256# 最后得到特征图的大小为下采样4倍,输出通道256的featuremaplayers.append(block(self.inplanes, planes))return nn.Sequential(*layers)
类中 = 4, self. = 64 != 64 *4 执行操作 。注意这里并没有对模型进行下采样,= 1,只是沿用了的名称,叫成了 。
的搭建如下代码:
class Bottleneck(nn.Module):expansion = 4def __init__(self, inplanes, planes, stride=1, downsample=None):super(Bottleneck, self).__init__()self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)self.bn1 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,padding=1, bias=False)self.bn2 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)self.conv3 = nn.Conv2d(planes, planes * self.expansion, kernel_size=1,bias=False)self.bn3 = nn.BatchNorm2d(planes * self.expansion,momentum=BN_MOMENTUM)self.relu = nn.ReLU(inplace=True)self.downsample = downsampleself.stride = stridedef forward(self, x):residual = xout = self.conv1(x)out = self.bn1(out)out = self.relu(out)out = self.conv2(out)out = self.bn2(out)out = self.relu(out)out = self.conv3(out)out = self.bn3(out)if self.downsample is not None:residual = self.downsample(x)out += residualout = self.relu(out)return out
其中的输入为,输出为4倍的 。
配置文件
STAGE2:NUM_MODULES: 1NUM_BRANCHES: 2BLOCK: BASICNUM_BLOCKS:- 4- 4NUM_CHANNELS:- 32- 64FUSE_METHOD: SUM
函数
x_list = []# NUM_BRANCHES = 2for i in range(self.stage2_cfg['NUM_BRANCHES']):if self.transition1[i] is not None:x_list.append(self.transition1[i](x))else:x_list.append(x)y_list = self.stage2(x_list)
- 人工神经网络分为哪两类,几种神经网络的区别
- 了解ResNet
- 经典卷积神经网络——resnet
- JAVA 3层架构及其实例文件/代码规范
- C++ 单元测试与代码覆盖率测试方法
- [计算机网络]IP协议
- 五 CNN经典网络模型:ResNet简介及代码实现(PyTorch超详细注释版
- 完整的ResNet代码
- 深度学习_经典网络_ResNet详解及常见问题总结
- 三 深度学习笔记:神经网络之九种激活函数Sigmoid、tanh、ReLU、R