princeton-vl / pytorch_stacked_hourglass

Pytorch implementation of the ECCV 2016 paper "Stacked Hourglass Networks for Human Pose Estimation"
BSD 3-Clause "New" or "Revised" License
465 stars 94 forks source link

I feel that the code of hourglass structure doesn't match the figure in paper #41

Closed myalos closed 2 years ago

myalos commented 2 years ago

Thanks for sharing! I was quite confused when i saw the code of hourglass. Since in the Fig3. of the paper, it seems that residual module happens before the pooling layer, that is, self.low1(x) precede self.pool1(x). I think the code might be

class Hourglass(nn.Module):
    def __init__(self, n, f, bn=None, increase=0):
        super(Hourglass, self).__init__()
        nf = f + increase
        self.up1 = Residual(f, f)
        # Lower branch
        self.pool1 = Pool(2, 2)
        self.low1 = Residual(f, nf)
        self.n = n
        # Recursive hourglass
        if self.n > 1:
            self.low2 = Hourglass(n-1, nf, bn=bn)
        else:
            self.low2 = nn.Sequential(Residual(nf, nf), Residual(nf, nf), Residual(nf, nf)) # modified
        self.low3 = Residual(nf, f)
        self.up2 = nn.Upsample(scale_factor=2, mode='nearest')

    def forward(self, x):
        up1  = self.up1(x)
        low1 = self.low1(x) # modified
        pool1 = self.pool1(low1) # modified
        low2 = self.low2(poo1) # modified
        up2  = self.up2(low2) # modified
        low3 = self.low3(up1  + up2) # modified
        return low3 # modified

am i wrong? where is the wrong place?

Dstudying commented 2 years ago

https://github.com/raymon-tian/hourglass-facekeypoints-detection Under this GitHub, models.py file is another way to implement hourglass. In fact, the core is to use recursion to build hourglass. I hope I can help you.

crockwell commented 2 years ago

Thanks for your suggestions, this is awesome! The examples shared change a few things at once; are you saying they are logically equivalent to my implementation and the structure is just different? Or are you saying they are logically different?

myalos commented 2 years ago

Thanks for your help ^ w ^