2019CVPR论文 HIgh Resolution Representation Learning for Human Pose Estimation代码解读

以下简称HRnet

这篇论文我拖更了好久,早在半年前我就说我要更新和这篇文献相关的代码研读,一直是懒,然后代码太长,分析代码真的要有决心+耐心+毅力,不然的话很容易放弃的,一件事情你做了百分之99就等同于没有做,行百里者半九十,就是这个道理,希望所有在这个领域内的小白通过阅读文献,编写代码来提升自己,相信你自己,你挺棒的。

HRnet由最基本的三种块构成。第一种是普通的3x3的卷积它的结构如下。

它的代码如下

def conv3x3(in_planes, out_planes, stride=1):
    """3x3 convolution with padding"""
    return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
                     padding=1, bias=False)

第二种是BasicBlock,它的结构如下。

当inchannels和outchannels不想等时就进行将采样。它的代码如下

class BasicBlock(nn.Module):
    expansion = 1

    def __init__(self, inplanes, planes, stride=1, downsample=None):
        super(BasicBlock, self).__init__()
        self.conv1 = conv3x3(inplanes, planes, stride)
        self.bn1 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
        self.relu = nn.ReLU(inplace=True)
        self.conv2 = conv3x3(planes, planes)
        self.bn2 = nn.BatchNorm2d(planes, momentum=BN_MOMENTUM)
        self.downsample = downsample
        self.stride = stride

    def forward(self, x):
        residual = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)

        if self.downsample is not None:
            residual = self.downsample(x)

        out += residual
        out = self.relu(out)

        return out

累,剩下的我慢慢写吧

猜你喜欢

转载自www.cnblogs.com/daremosiranaihana/p/13198239.html