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

pnnx convert nn.Upsample with recompute_scale_factor=True #5169

Merged
merged 6 commits into from
Nov 27, 2023

Conversation

nihui
Copy link
Member

@nihui nihui commented Nov 22, 2023

No description provided.

@nihui
Copy link
Member Author

nihui commented Nov 27, 2023

import torch
import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

        self.up_0 = nn.Upsample(scale_factor=(1,2.44), mode='bilinear', align_corners=False, recompute_scale_factor=False)
        self.up_1 = nn.Upsample(scale_factor=(1,2.44), mode='bilinear', align_corners=False, recompute_scale_factor=True)
        self.up_2 = nn.Upsample(scale_factor=(1,2.44), mode='bilinear', align_corners=True, recompute_scale_factor=False)
        self.up_3 = nn.Upsample(scale_factor=(1,2.44), mode='bilinear', align_corners=True, recompute_scale_factor=True)

    def forward(self, x):
        out0 = self.up_0(x)
        out1 = self.up_1(x)
        out2 = self.up_2(x)
        out3 = self.up_3(x)
        return out0, out1, out2, out3

def test():
    net = Model()
    net.eval()

    torch.manual_seed(0)
    x = torch.rand(1, 1, 1, 2)

    out0, out1, out2, out3 = net(x)

    print(out0)
    print(out1)
    print(out2)
    print(out3)

if __name__ == "__main__":
    if test():
        exit(0)
    else:
        exit(1)

# [nihui@nihuini-LC2 test]$ python test.py
# tensor([[[[0.4963, 0.5275, 0.6389, 0.7504]]]])
# tensor([[[[0.4963, 0.5642, 0.7002, 0.7682]]]])
# tensor([[[[0.4963, 0.5869, 0.6776, 0.7682]]]])
# tensor([[[[0.4963, 0.5869, 0.6776, 0.7682]]]])

@nihui nihui merged commit 3785921 into Tencent:master Nov 27, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant