Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bilinear Upsampler Implementation #30

Open
sr-frost opened this issue Mar 28, 2020 · 1 comment
Open

Bilinear Upsampler Implementation #30

sr-frost opened this issue Mar 28, 2020 · 1 comment

Comments

@sr-frost
Copy link

Hi, it's really refreshing to see signal processing principles used in deep networks. I have a question about the upsampling mechanism.

After going through the original code and a related issue #28, following is my attempt to implement a bilinear-upsampler:

class BilinearUpsample(nn.Module):
    def __init__(self, channels=None, interpolation_factor=2):
        super(BilinearUpsample, self).__init__()
        self.channels = channels
        self.stride = interpolation_factor

        lpf = torch.tensor([[1., 2., 1.],
                            [2., 4., 2.],
                            [1., 2., 1.]])
        lpf = lpf/torch.sum(lpf)*4
        lpf = lpf.unsqueeze(dim=0).unsqueeze(dim=0)
        lpf = lpf.repeat([self.channels, 1, 1, 1])
        self.register_buffer('lpf', lpf)

    def forward(self, x):
            return F.conv_transpose2d(input = x, weight = self.lpf, stride=self.stride, padding = 1, output_padding=1, groups=self.channels)

Is this implementation correct ?
The result seems very different from PyTorch bilinear interpolation.

Using

BilinearUpsample(channels=num_channels)(a)

vs

F.interpolate(a, scale_factor=2, mode='bilinear', align_corners=True) 

returns very different output.

@hadaev8
Copy link

hadaev8 commented Nov 5, 2021

Shouldnt you have 4x4 kernel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants