| 838 | |
| 839 | |
| 840 | class Resize(nn.Module): |
| 841 | def __init__(self, in_channels=None, learned=False, mode="bilinear"): |
| 842 | super().__init__() |
| 843 | self.with_conv = learned |
| 844 | self.mode = mode |
| 845 | if self.with_conv: |
| 846 | print(f"Note: {self.__class__.__name} uses learned downsampling and will ignore the fixed {mode} mode") |
| 847 | raise NotImplementedError() |
| 848 | assert in_channels is not None |
| 849 | # no asymmetric padding in torch conv, must do it ourselves |
| 850 | self.conv = torch.nn.Conv2d(in_channels, |
| 851 | in_channels, |
| 852 | kernel_size=4, |
| 853 | stride=2, |
| 854 | padding=1) |
| 855 | |
| 856 | def forward(self, x, scale_factor=1.0): |
| 857 | if scale_factor==1.0: |
| 858 | return x |
| 859 | else: |
| 860 | x = torch.nn.functional.interpolate(x, mode=self.mode, align_corners=False, scale_factor=scale_factor) |
| 861 | return x |
nothing calls this directly
no outgoing calls
no test coverage detected