jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def forward(self, x):
        if self.use_arcface:
            conv_feat = self.net.forward_features(x)
            #input = self.flatten(self.pool(conv_feat))
            xa = t.interpolate(x, [144, 144], mode='bilinear', align_corners=False)
            xa = xa[:,:,8:120,16:128]
            z = self.neta(xa)
            z = self.mlp(z)

            c = conv_feat
            for i in range(len(self.style_blocks)):
                c = self.style_blocks[i](c, z)
            feat3 = c
            feat2 = self.branch2d(conv_feat)
            conv_feat = torch.cat([feat3, feat2], dim=1)
            feat = self.flatten(self.pool(conv_feat))
            pred = self.fc(feat)

        elif self.no_gap:
            y = self.net.forward_features(x)
            pred = self.no_gap_output(y)
        else:
            pred = self.net(x)
            if self.use_eyes:
                eye_w1 = x.shape[3]//8
                eye_w2 = x.shape[3] - wa
                hstep = x.shape[2]//8
                eye_h1 = hstep*2
                eye_h2 = hstep*4
                x_eye = x[:,:,eye_h1:eye_h2,eye_w1:eye_w2]
                feate = self.nete(x_eye)
                #print(pred.shape, feate.shape)
                feat = torch.cat((pred,feate), 1)
                pred = self.fc(feat)
        return pred
//  [python]
def forward(self, x):
        if self.use_arcface:
            conv_feat = self.net.forward_features(x)
            #input = self.flatten(self.pool(conv_feat))
            xa = F.interpolate(x, [144, 144], mode='bilinear', align_corners=False)
            xa = xa[:,:,8:120,16:128]
            z = self.neta(xa)
            z = self.mlp(z)

            c = conv_feat
            for i in range(len(self.style_blocks)):
                c = self.style_blocks[i](c, z)
            feat3 = c
            feat2 = self.branch2d(conv_feat)
            conv_feat = torch.cat([feat3, feat2], dim=1)
            feat = self.flatten(self.pool(conv_feat))
            pred = self.fc(feat)

        elif self.no_gap:
            y = self.net.forward_features(x)
            pred = self.no_gap_output(y)
        else:
            pred = self.net(x)
            if self.use_eyes:
                eye_w1 = x.shape[3]//8
                eye_w2 = x.shape[3] - wa
                hstep = x.shape[2]//8
                eye_h1 = hstep*2
                eye_h2 = hstep*4
                x_eye = x[:,:,eye_h1:eye_h2,eye_w1:eye_w2]
                feate = self.nete(x_eye)
                #print(pred.shape, feate.shape)
                feat = torch.cat((pred,feate), 1)
                pred = self.fc(feat)
        return pred
//  [python]
def test_upsamplingNearest1d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2)
        in_uint8_t = torch.ones(1, 1, 2, dtype=torch.uint8)
        with warnings.catch_warnings(record=True) as w:
            out_t = m(in_t)
            out_uint8_t = m(in_t)
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)
        # TODO(#38095): Replace assertEqualIgnoreType. See issue #38095
        self.assertEqualIgnoreType(torch.ones(1, 1, 4, dtype=torch.uint8), out_uint8_t.data)

        input = torch.randn(1, 1, 2, requires_grad=True)
        gradcheck(lambda x: nn.functional.upsample(x, scale_factor=4, mode='nearest'), [input])
//  [python]
def test_upsamplingNearest1d(self):
        m = nn.Upsample(size=4, mode='nearest')
        in_t = torch.ones(1, 1, 2)
        in_uint8_t = torch.ones(1, 1, 2, dtype=torch.uint8)
        with warnings.catch_warnings(record=True) as w:
            out_t = m(in_t)
            out_uint8_t = m(in_t)
        self.assertEqual(torch.ones(1, 1, 4), out_t.data)
        # TODO(#38095): Replace assertEqualIgnoreType. See issue #38095
        self.assertEqualIgnoreType(torch.ones(1, 1, 4, dtype=torch.uint8), out_uint8_t.data)

        input = torch.randn(1, 1, 2, requires_grad=True)
        gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
//  [python]
def test_upsamplingLinear1d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='linear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size), out_t.data)

                input = torch.randn(1, 1, 2, requires_grad=True)
                gradcheck(lambda x: t.interpolate(x, out_size, **kwargs), (input,))
//  [python]
def test_upsamplingLinear1d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='linear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size), out_t.data)

                input = torch.randn(1, 1, 2, requires_grad=True)
                gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), (input,))
//  [python]
def test_upsamplingBilinear2d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='bilinear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size, out_size), out_t.data)

                input = torch.randn(1, 1, 2, 2, requires_grad=True)
                gradcheck(lambda x: t.interpolate(x, out_size, **kwargs), [input])
//  [python]
def test_upsamplingBilinear2d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='bilinear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size, out_size), out_t.data)

                input = torch.randn(1, 1, 2, 2, requires_grad=True)
                gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
//  [python]
def color_correction(gt, in_put, output, scale_factor=4):
    ds_gt = t.interpolate(gt, scale_factor=1.0 / scale_factor, mode='bilinear', align_corners=False)
    output_cor = match_channel_colors(ds_gt, in_put, output)
    return output_cor
//  [python]
def color_correction(gt, in_put, output, scale_factor=4):
    ds_gt = F.interpolate(gt, scale_factor=1.0 / scale_factor, mode='bilinear', align_corners=False, recompute_scale_factor=True)
    output_cor = match_channel_colors(ds_gt, in_put, output)
    return output_cor
//  [python]
def test_upsamplingNearest2d(self):
        for memory_format in [torch.contiguous_format, torch.channels_last]:
            m = nn.Upsample(size=4, mode='nearest')
            in_t = torch.ones(1, 1, 2, 2).contiguous(memory_format=memory_format)
            in_uint8_t = torch.ones(1, 1, 2, 2, dtype=torch.uint8).contiguous(memory_format=memory_format)
            with warnings.catch_warnings(record=True) as w:
                out_t = m(in_t)
                out_uint8_t = m(in_uint8_t)
            self.assertEqual(torch.ones(1, 1, 4, 4).contiguous(memory_format=memory_format), out_t.data)
            self.assertEqual(torch.ones(1, 1, 4, 4, dtype=torch.uint8).contiguous(memory_format=memory_format), out_uint8_t.data)

            input = torch.randn(1, 1, 2, 2, requires_grad=True).contiguous(memory_format=memory_format)
            self.assertEqual(
                nn.functional.interpolate(input, 4, mode='nearest'),
                nn.functional.interpolate(input, scale_factor=2, mode='nearest'))
            gradcheck(lambda x: nn.functional.interpolate(x, 4, mode='nearest'), [input])
            gradgradcheck(lambda x: nn.functional.interpolate(x, 4, mode='nearest'), [input])
//  [python]
def test_upsamplingNearest2d(self):
        for memory_format in [torch.contiguous_format, torch.channels_last]:
            m = nn.Upsample(size=4, mode='nearest')
            in_t = torch.ones(1, 1, 2, 2).contiguous(memory_format=memory_format)
            in_uint8_t = torch.ones(1, 1, 2, 2, dtype=torch.uint8).contiguous(memory_format=memory_format)
            with warnings.catch_warnings(record=True) as w:
                out_t = m(in_t)
                out_uint8_t = m(in_uint8_t)
            self.assertEqual(torch.ones(1, 1, 4, 4).contiguous(memory_format=memory_format), out_t.data)
            self.assertEqual(torch.ones(1, 1, 4, 4, dtype=torch.uint8).contiguous(memory_format=memory_format), out_uint8_t.data)

            input = torch.randn(1, 1, 2, 2, requires_grad=True).contiguous(memory_format=memory_format)
            self.assertEqual(
                F.interpolate(input, 4, mode='nearest'),
                F.interpolate(input, scale_factor=2, mode='nearest'))
            gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
            gradgradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
//  [python]
def forward(self, x):
        z = self.model.encode(x).sample()
        z = z * self.scale_factor
        noise_level = torch.randint(
            0, self.max_noise_level, (x.shape[0], ), device=x.device).long()
        z = self.q_sample(z, noise_level)
        if self.out_size is not None:
            z = torch.nn.functional.interpolate(
                z, size=self.out_size,
                mode='nearest')  # TODO: experiment with mode
        # z = z.repeat_interleave(2, -2).repeat_interleave(2, -1)
        return z, noise_level
//  [python]
def test_upsamplingNearest3d(self):
        for memory_format in [torch.contiguous_format, torch.channels_last_3d]:
            m = nn.Upsample(size=4, mode='nearest')
            in_t = torch.ones(1, 1, 2, 2, 2).contiguous(memory_format=memory_format)
            in_uint8_t = torch.ones(1, 1, 2, 2, 2, dtype=torch.uint8).contiguous(memory_format=memory_format)
            with warnings.catch_warnings(record=True) as w:
                out_t = m(in_t)
                out_uint8_t = m(in_uint8_t)
            self.assertEqual(torch.ones(1, 1, 4, 4, 4).contiguous(memory_format=memory_format), out_t.data)
            self.assertEqual(torch.ones(1, 1, 4, 4, 4, dtype=torch.uint8).contiguous(memory_format=memory_format), out_uint8_t.data)

            input = torch.randn(1, 1, 2, 2, 2, requires_grad=True).contiguous(memory_format=memory_format)
            gradcheck(lambda x: nn.functional.upsample(x, scale_factor=4, mode='nearest'), [input])
//  [python]
def test_upsamplingNearest3d(self):
        for memory_format in [torch.contiguous_format, torch.channels_last_3d]:
            m = nn.Upsample(size=4, mode='nearest')
            in_t = torch.ones(1, 1, 2, 2, 2).contiguous(memory_format=memory_format)
            in_uint8_t = torch.ones(1, 1, 2, 2, 2, dtype=torch.uint8).contiguous(memory_format=memory_format)
            with warnings.catch_warnings(record=True) as w:
                out_t = m(in_t)
                out_uint8_t = m(in_uint8_t)
            self.assertEqual(torch.ones(1, 1, 4, 4, 4).contiguous(memory_format=memory_format), out_t.data)
            self.assertEqual(torch.ones(1, 1, 4, 4, 4, dtype=torch.uint8).contiguous(memory_format=memory_format), out_uint8_t.data)

            input = torch.randn(1, 1, 2, 2, 2, requires_grad=True).contiguous(memory_format=memory_format)
            gradcheck(lambda x: F.interpolate(x, 4, mode='nearest'), [input])
//  [python]
def test_upsamplingTrilinear3d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='trilinear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2, 2, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size, out_size, out_size), out_t.data)

                input = torch.randn(1, 1, 2, 2, 2, requires_grad=True)
                self.assertEqual(
                    t.upsample(input, (out_size, out_size, out_size), **kwargs),
                    t.upsample(input, scale_factor=scale_factor, **kwargs))
                gradcheck(lambda x: t.upsample(x, out_size, **kwargs), [input])
                gradgradcheck(lambda x: t.upsample(x, out_size, **kwargs), [input])
//  [python]
def test_upsamplingTrilinear3d(self):
        for align_corners in [True, False]:
            kwargs = dict(mode='trilinear', align_corners=align_corners)

            # test float scale factor up & downsampling
            for scale_factor in [0.5, 1.5, 2]:
                m = nn.Upsample(scale_factor=scale_factor, **kwargs)
                in_t = torch.ones(1, 1, 2, 2, 2)
                out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                with warnings.catch_warnings(record=True) as w:
                    out_t = m(in_t)
                self.assertEqual(torch.ones(1, 1, out_size, out_size, out_size), out_t.data)

                input = torch.randn(1, 1, 2, 2, 2, requires_grad=True)
                self.assertEqual(
                    F.interpolate(input, (out_size, out_size, out_size), **kwargs),
                    F.interpolate(input, scale_factor=scale_factor, **kwargs))
                gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
                gradgradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
//  [python]
def init_bg_density_from_bg_density(self, bg_density):
        print("\n", "- "*3 + "initing bg_density from bg_density" + " -"*3, "\n")
        if bg_density.shape != self.bg_density.grid.shape:
            if self.init_bg_density_fix:
                bg_density = t.nn.functional.interpolate(bg_density, size=tuple(self.world_size_bg), mode='trilinear', align_corners=True)
            else:
                bg_density = t.nn.functional.interpolate(bg_density, size=tuple(self.world_size), mode='trilinear', align_corners=True)
        self.bg_density.grid.data = bg_density.to(self.bg_density.grid)
        if self.mask_cache is not None:
            self._set_nonempty_mask()
//  [python]
def init_bg_density_from_bg_density(self, bg_density):
        print("\n", "- "*3 + "initing bg_density from bg_density" + " -"*3, "\n")
        if bg_density.shape != self.bg_density.grid.shape:
            if self.init_bg_density_fix:
                bg_density = F.interpolate(bg_density, size=tuple(self.world_size_bg), mode='trilinear', align_corners=True)
            else:
                bg_density = F.interpolate(bg_density, size=tuple(self.world_size), mode='trilinear', align_corners=True)
        self.bg_density.grid.data = bg_density.to(self.bg_density.grid)
        if self.mask_cache is not None:
            self._set_nonempty_mask()
//  [python]
def init_sdf_from_sdf(self, sdf0=None, smooth=False, reduce=1., ksize=3, sigma=1., zero2neg=True):
        print("\n", "- "*3 + "initing sdf from sdf" + " -"*3, "\n")
        if sdf0.shape != self.sdf.grid.shape:
            sdf0 = t.interpolate(sdf0, size=tuple(self.world_size), mode='trilinear', align_corners=True)
        if smooth:
            m = self._gaussian_3dconv(ksize, sigma)
            sdf_data = m(sdf0 / reduce)
            self.sdf.grid = torch.nn.Parameter(sdf_data).to(self.sdf.grid) / reduce
        else:
            self.sdf.grid.data = sdf0.to(self.sdf.grid) / reduce # + self.act_shift
        if self.mask_cache is not None:
            self._set_nonempty_mask()
        if self.smooth_scale:
            m = self._gaussian_3dconv(ksize=5, sigma=1)
            with torch.no_grad():
                self.sdf.grid = torch.nn.Parameter(m(self.sdf.grid.data)).cuda()
        self.gradient = self.neus_sdf_gradient()
//  [python]
def init_sdf_from_sdf(self, sdf0=None, smooth=False, reduce=1., ksize=3, sigma=1., zero2neg=True):
        print("\n", "- "*3 + "initing sdf from sdf" + " -"*3, "\n")
        if sdf0.shape != self.sdf.grid.shape:
            sdf0 = F.interpolate(sdf0, size=tuple(self.world_size), mode='trilinear', align_corners=True)
        if smooth:
            m = self._gaussian_3dconv(ksize, sigma)
            sdf_data = m(sdf0 / reduce)
            self.sdf.grid = torch.nn.Parameter(sdf_data).to(self.sdf.grid) / reduce
        else:
            self.sdf.grid.data = sdf0.to(self.sdf.grid) / reduce # + self.act_shift
        if self.mask_cache is not None:
            self._set_nonempty_mask()
        if self.smooth_scale:
            m = self._gaussian_3dconv(ksize=5, sigma=1)
            with torch.no_grad():
                self.sdf.grid = torch.nn.Parameter(m(self.sdf.grid.data)).cuda()
        self.gradient = self.neus_sdf_gradient()
//  [python]
def test_upsamplingBicubic2d(self):
        # test output against known input: align_corners=False result must match opencv
        in_t = torch.arange(8.).view(1, 2, 2, 2)
        expected_out_t = torch.Tensor(
            [[[[-0.31641, 0.01562, 0.56250, 0.89453],
              [0.34766, 0.67969, 1.22656, 1.55859],
              [1.44141, 1.77344, 2.32031, 2.65234],
              [2.10547, 2.43750, 2.98438, 3.31641]],

             [[3.68359, 4.01562, 4.56250, 4.89453],
              [4.34766, 4.67969, 5.22656, 5.55859],
              [5.44141, 5.77344, 6.32031, 6.65234],
              [6.10547, 6.43750, 6.98438, 7.31641]]]])
        out_t = t.imresize(in_t, scale_factor=2, mode='bicubic', align_corners=False)
        torch.set_printoptions(precision=5)
        # TODO(#38095): Replace assertEqualIgnoreType. See issue #38095
        self.assertEqualIgnoreType(out_t, expected_out_t, atol=1e-5, rtol=0)


        device_list = ['cpu']
        if TEST_CUDA:
            device_list.append('cuda')

        for align_corners in [True, False]:
            kwargs = dict(mode='bicubic', align_corners=align_corners)
            # test float scale factor up & downsampling
            for device in device_list:
                for scale_factor in [0.5, 1.5, 2]:
                    in_t = torch.ones(2, 2, 2, 2).to(device)
                    out_t = t.imresize(in_t, scale_factor=scale_factor, **kwargs)
                    out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                    self.assertEqual(torch.ones(2, 2, out_size, out_size), out_t.data,
                                     atol=1e-5, rtol=0)

                    input = torch.randn(2, 2, 2, 2, requires_grad=True)
                    gradcheck(lambda x: t.imresize(x, out_size, **kwargs), [input])
//  [python]
def test_upsamplingBicubic2d(self):
        # test output against known input: align_corners=False result must match opencv
        in_t = torch.arange(8.).view(1, 2, 2, 2)
        expected_out_t = torch.Tensor(
            [[[[-0.31641, 0.01562, 0.56250, 0.89453],
              [0.34766, 0.67969, 1.22656, 1.55859],
              [1.44141, 1.77344, 2.32031, 2.65234],
              [2.10547, 2.43750, 2.98438, 3.31641]],

             [[3.68359, 4.01562, 4.56250, 4.89453],
              [4.34766, 4.67969, 5.22656, 5.55859],
              [5.44141, 5.77344, 6.32031, 6.65234],
              [6.10547, 6.43750, 6.98438, 7.31641]]]])
        out_t = F.interpolate(in_t, scale_factor=2, mode='bicubic', align_corners=False)
        torch.set_printoptions(precision=5)
        # TODO(#38095): Replace assertEqualIgnoreType. See issue #38095
        self.assertEqualIgnoreType(out_t, expected_out_t, atol=1e-5, rtol=0)


        device_list = ['cpu']
        if TEST_CUDA:
            device_list.append('cuda')

        for align_corners in [True, False]:
            kwargs = dict(mode='bicubic', align_corners=align_corners)
            # test float scale factor up & downsampling
            for device in device_list:
                for scale_factor in [0.5, 1.5, 2]:
                    in_t = torch.ones(2, 2, 2, 2).to(device)
                    out_t = F.interpolate(in_t, scale_factor=scale_factor, **kwargs)
                    out_size = int(math.floor(in_t.shape[-1] * scale_factor))
                    self.assertEqual(torch.ones(2, 2, out_size, out_size), out_t.data,
                                     atol=1e-5, rtol=0)

                    input = torch.randn(2, 2, 2, 2, requires_grad=True)
                    gradcheck(lambda x: F.interpolate(x, out_size, **kwargs), [input])
//  [python]
def _pyramid_up(self, input, size, pad_mode='constant'):
        if not len(input.shape) == 4:
            raise ValueError(f'Invalid img shape, we expect BCHW, got: {input.shape}')
        # upsample
        img_up = t.nn.functional.interpolate(input, size=size, mode='nearest', )
        # blur
        img_pad = F.pad(img_up, (2,2,2,2), mode=pad_mode)
        img_blur = kornia_filter2d(img_pad, kernel=self.kernel)
        return img_blur
//  [python]
def _pyramid_up(self, input, size, pad_mode='constant'):
        if not len(input.shape) == 4:
            raise ValueError(f'Invalid img shape, we expect BCHW, got: {input.shape}')
        # upsample
        img_up = F.interpolate(input, size=size, mode='nearest', )
        # blur
        img_pad = F.pad(img_up, (2,2,2,2), mode=pad_mode)
        img_blur = kornia_filter2d(img_pad, kernel=self.kernel)
        return img_blur
//  [python]
def scale_volume_grid(self, num_voxels, num_voxels_bg=0):
        print('scale_volume_grid start')
        ori_world_size = self.world_size
        self._set_grid_resolution(num_voxels, num_voxels_bg)
        print('scale_volume_grid scale world_size from', ori_world_size, 'to', self.world_size)
        if num_voxels_bg > 0:
            ori_world_size_bg = self.world_size_bg
            print('scale_volume_grid scale [background] world_size from', ori_world_size_bg, 'to', self.world_size_bg)

        self.sdf.scale_volume_grid(self.world_size)
        self.bg_density.scale_volume_grid(self.world_size_bg)
        if self.k0_dim > 0:
            self.k0.scale_volume_grid(self.world_size)
        if self.bg_k0_dim > 0:
            self.bg_k0.scale_volume_grid(self.world_size_bg)
        self.density = torch.nn.Parameter(
            t.upsample(self.density.data, size=tuple(self.world_size), mode='trilinear'))
        if self.mask_cache is not None:
            self._set_nonempty_mask()
        self._set_sphere_nonempty_mask()
        print('scale_volume_grid finish')
//  [python]
def scale_volume_grid(self, num_voxels, num_voxels_bg=0):
        print('scale_volume_grid start')
        ori_world_size = self.world_size
        self._set_grid_resolution(num_voxels, num_voxels_bg)
        print('scale_volume_grid scale world_size from', ori_world_size, 'to', self.world_size)
        if num_voxels_bg > 0:
            ori_world_size_bg = self.world_size_bg
            print('scale_volume_grid scale [background] world_size from', ori_world_size_bg, 'to', self.world_size_bg)

        self.sdf.scale_volume_grid(self.world_size)
        self.bg_density.scale_volume_grid(self.world_size_bg)
        if self.k0_dim > 0:
            self.k0.scale_volume_grid(self.world_size)
        if self.bg_k0_dim > 0:
            self.bg_k0.scale_volume_grid(self.world_size_bg)
        self.density = torch.nn.Parameter(
            F.interpolate(self.density.data, size=tuple(self.world_size), mode='trilinear', align_corners=True))
        if self.mask_cache is not None:
            self._set_nonempty_mask()
        self._set_sphere_nonempty_mask()
        print('scale_volume_grid finish')
//  [python]
def inpaint(self, batch, seed, ddim_steps, num_samples=1, W=512, H=512):
        model = self.sampler.model

        prng = np.random.RandomState(seed)
        start_code = prng.randn(num_samples, model.first_stage_model.embed_dim, H // 8, W // 8)
        start_code = torch.from_numpy(start_code).to(device=self.device, dtype=torch.float32)

        c = model.get_first_stage_encoding(model.encode_first_stage(batch["masked_mel"]))
        cc = torch.nn.functional.interpolate(batch["mask"],
                                                size=c.shape[-2:])
        c = torch.cat((c, cc), dim=1) # (b,c+1,h,w) 1 is mask

        shape = (c.shape[1]-1,)+c.shape[2:]
        samples_ddim, _ = self.sampler.sample(S=ddim_steps,
                                            conditioning=c,
                                            batch_size=c.shape[0],
                                            shape=shape,
                                            verbose=False)
        x_samples_ddim = model.decode_first_stage(samples_ddim)


        mel = torch.clamp((batch["mel"]+1.0)/2.0,min=0.0, max=1.0)
        mask = torch.clamp((batch["mask"]+1.0)/2.0,min=0.0, max=1.0)
        predicted_mel = torch.clamp((x_samples_ddim+1.0)/2.0,min=0.0, max=1.0)
        inpainted = (1-mask)*mel+mask*predicted_mel
        inpainted = inpainted.cpu().numpy().squeeze()
        inapint_wav = self.vocoder.vocode(inpainted)

        return inpainted, inapint_wav
//  [python]
def forward(self, inputs, logdets):
        assert self.start_idx+1 < len(inputs)
        x0, x1 = inputs[self.start_idx: self.start_idx+2]
        logdet0, logdet1 = logdets[self.start_idx: self.start_idx+2]
        if self.direct == 'up':
            y10 = t.interpolate(x1, size=x0.shape[2:], mode='nearest') # interp first
            (scale0, bias0), dlogdet0 = self.affineParams(y10, forward_mode=True)
            z0, z1 = scale0*x0+bias0, x1
            z0 = self.conv1x1(z0) 
            dlogdet1 = 0
        else:
            (scale10, bias10), dlogdet10 = self.affineParams(x0, forward_mode=True)
            scale1, bias1, dlogdet1 = t.interpolate(scale10, size=x1.shape[2:], mode='nearest'),\
                                         t.interpolate(bias10, size=x1.shape[2:], mode='nearest'),\
                                             t.interpolate(dlogdet10, size=x1.shape[2:], mode='nearest') # interp after
            z0, z1 = x0, scale1*x1+bias1
            z1 = self.conv1x1(z1) 
            dlogdet0 = 0
        outputs = inputs[:self.start_idx]+(z0, z1)+inputs[self.start_idx+2:]
        out_logdets = logdets[:self.start_idx]+(logdet0+dlogdet0, logdet1+dlogdet1)+logdets[self.start_idx+2:]
        return outputs, out_logdets
//  [python]
def forward(self, inputs, logdets):
        assert self.start_idx+1 < len(inputs)
        x0, x1 = inputs[self.start_idx: self.start_idx+2]
        logdet0, logdet1 = logdets[self.start_idx: self.start_idx+2]
        if self.direct == 'up':
            y10 = F.interpolate(x1, size=x0.shape[2:], mode='nearest') # interp first
            (scale0, bias0), dlogdet0 = self.affineParams(y10, forward_mode=True)
            z0, z1 = scale0*x0+bias0, x1
            z0 = self.conv1x1(z0) 
            dlogdet1 = 0
        else:
            (scale10, bias10), dlogdet10 = self.affineParams(x0, forward_mode=True)
            scale1, bias1, dlogdet1 = F.interpolate(scale10, size=x1.shape[2:], mode='nearest'),\
                                         F.interpolate(bias10, size=x1.shape[2:], mode='nearest'),\
                                             F.interpolate(dlogdet10, size=x1.shape[2:], mode='nearest') # interp after
            z0, z1 = x0, scale1*x1+bias1
            z1 = self.conv1x1(z1) 
            dlogdet0 = 0
        outputs = inputs[:self.start_idx]+(z0, z1)+inputs[self.start_idx+2:]
        out_logdets = logdets[:self.start_idx]+(logdet0+dlogdet0, logdet1+dlogdet1)+logdets[self.start_idx+2:]
        return outputs, out_logdets
//  [python]
def forward(self, inputs, logdets):
        x0, x1, x2 = inputs[self.start_idx: self.start_idx+3]
        logdet0, logdet1, logdet2 = logdets[self.start_idx: self.start_idx+3]
        y01 = t.interpolate(x0, size=x1.shape[2:], mode='nearest')
        y21 = t.interpolate(x2, size=x1.shape[2:], mode='nearest')
        affine_input = torch.concat([y01, y21], dim=1) # b, 2*ch, h, w
        (scale1, bias1), dlogdet1 = self.affineParams(affine_input, forward_mode=True)
        z0, z1, z2 = x0, scale1*x1+bias1, x2
        z1 = self.conv1x1(z1)
        outputs = inputs[:self.start_idx]+(z0, z1, z2)+inputs[self.start_idx+3:]
        out_logdets = logdets[:self.start_idx]+(logdet0, logdet1+dlogdet1, logdet2)+logdets[self.start_idx+3:]
        return outputs, out_logdets
//  [python]
def forward(self, inputs, logdets):
        x0, x1, x2 = inputs[self.start_idx: self.start_idx+3]
        logdet0, logdet1, logdet2 = logdets[self.start_idx: self.start_idx+3]
        y01 = F.interpolate(x0, size=x1.shape[2:], mode='nearest')
        y21 = F.interpolate(x2, size=x1.shape[2:], mode='nearest')
        affine_input = torch.concat([y01, y21], dim=1) # b, 2*ch, h, w
        (scale1, bias1), dlogdet1 = self.affineParams(affine_input, forward_mode=True)
        z0, z1, z2 = x0, scale1*x1+bias1, x2
        z1 = self.conv1x1(z1)
        outputs = inputs[:self.start_idx]+(z0, z1, z2)+inputs[self.start_idx+3:]
        out_logdets = logdets[:self.start_idx]+(logdet0, logdet1+dlogdet1, logdet2)+logdets[self.start_idx+3:]
        return outputs, out_logdets
//  [python]
def _forward(self, level, inp):
        # upper branch
        up1 = inp 
        up1 = self._modules['b1_' + str(level)](up1)

        # lower branch
        low1 = F.avg_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)

        up2 = F.upsample(low3, scale_factor=2, mode='bicubic', align_corners=True)
        # up2 = F.upsample(low3, scale_factor=2, mode='bilinear')

        return up1 + up2
//  [python]
def _forward(self, level, inp):
        # upper branch
        up1 = inp 
        up1 = self._modules['b1_' + str(level)](up1)

        # lower branch
        low1 = F.avg_pool2d(inp, 2, stride=2)
        low1 = self._modules['b2_' + str(level)](low1)

        if level > 1:
            low2 = self._forward(level - 1, low1)
        else:
            low2 = low1
            low2 = self._modules['b2_plus_' + str(level)](low2)

        low3 = low2
        low3 = self._modules['b3_' + str(level)](low3)

        up2 = F.interpolate(low3, scale_factor=2, mode='bicubic', align_corners=True)
        # up2 = F.interpolate(low3, scale_factor=2, mode='bilinear')

        return up1 + up2
//  [python]
def inverse(self, outputs, logdets):
        assert self.start_idx+1 < len(outputs)
        z0, z1 = outputs[self.start_idx: self.start_idx+2]
        logdet0, logdet1 = logdets[self.start_idx: self.start_idx+2]
        if self.direct == 'up':
            z0 = self.conv1x1.inverse(z0)
            z10 = t.nn.functional.interpolate(z1, size=z0.shape[2:], mode='nearest') # interp first
            (scale0, bias0), dlogdet0 = self.affineParams(z10, forward_mode=False)
            x0, x1 = (z0-bias0)/scale0, z1
            dlogdet1 = 0
        else:
            z1 = self.conv1x1.inverse(z1)
            (scale01, bias01), dlogdet01 = self.affineParams(z0, forward_mode=False)
            scale1, bias1, dlogdet1 = t.nn.functional.interpolate(scale01, size=z1.shape[2:], mode='nearest'),\
                                         t.nn.functional.interpolate(bias01, size=z1.shape[2:], mode='nearest'),\
                                             t.nn.functional.interpolate(dlogdet01, size=z1.shape[2:], mode='nearest') # interp after
            x0, x1 = z0, (z1-bias1)/scale1
            dlogdet0 = 0
        inputs = outputs[:self.start_idx]+(x0, x1)+outputs[self.start_idx+2:]
        in_logdets = logdets[:self.start_idx]+(logdet0-dlogdet0, logdet1-dlogdet1)+logdets[self.start_idx+2:]
        return inputs, in_logdets
//  [python]
def inverse(self, outputs, logdets):
        assert self.start_idx+1 < len(outputs)
        z0, z1 = outputs[self.start_idx: self.start_idx+2]
        logdet0, logdet1 = logdets[self.start_idx: self.start_idx+2]
        if self.direct == 'up':
            z0 = self.conv1x1.inverse(z0)
            z10 = F.interpolate(z1, size=z0.shape[2:], mode='nearest') # interp first
            (scale0, bias0), dlogdet0 = self.affineParams(z10, forward_mode=False)
            x0, x1 = (z0-bias0)/scale0, z1
            dlogdet1 = 0
        else:
            z1 = self.conv1x1.inverse(z1)
            (scale01, bias01), dlogdet01 = self.affineParams(z0, forward_mode=False)
            scale1, bias1, dlogdet1 = F.interpolate(scale01, size=z1.shape[2:], mode='nearest'),\
                                         F.interpolate(bias01, size=z1.shape[2:], mode='nearest'),\
                                             F.interpolate(dlogdet01, size=z1.shape[2:], mode='nearest') # interp after
            x0, x1 = z0, (z1-bias1)/scale1
            dlogdet0 = 0
        inputs = outputs[:self.start_idx]+(x0, x1)+outputs[self.start_idx+2:]
        in_logdets = logdets[:self.start_idx]+(logdet0-dlogdet0, logdet1-dlogdet1)+logdets[self.start_idx+2:]
        return inputs, in_logdets
//  [python]
def inverse(self, outputs, logdets):
        z0, z1, z2 = outputs[self.start_idx: self.start_idx+3]
        logdet0, logdet1, logdet2 = logdets[self.start_idx: self.start_idx+3]
        z1 = self.conv1x1.inverse(z1)
        z01 = t.interpolate(z0, size=z1.shape[2:], mode='nearest')
        z21 = t.interpolate(z2, size=z1.shape[2:], mode='nearest')
        affine_input = torch.concat([z01, z21], dim=1) # b, 2*ch, h, w
        (scale1, bias1), dlogdet1 = self.affineParams(affine_input, forward_mode=False)
        x0, x1, x2 = z0, (z1-bias1)/scale1, z2
        inputs = outputs[:self.start_idx]+(x0, x1, x2)+outputs[self.start_idx+3:]
        in_logdets = logdets[:self.start_idx]+(logdet0, logdet1-dlogdet1, logdet2)+logdets[self.start_idx+3:]
        return inputs, in_logdets
//  [python]
def inverse(self, outputs, logdets):
        z0, z1, z2 = outputs[self.start_idx: self.start_idx+3]
        logdet0, logdet1, logdet2 = logdets[self.start_idx: self.start_idx+3]
        z1 = self.conv1x1.inverse(z1)
        z01 = F.interpolate(z0, size=z1.shape[2:], mode='nearest')
        z21 = F.interpolate(z2, size=z1.shape[2:], mode='nearest')
        affine_input = torch.concat([z01, z21], dim=1) # b, 2*ch, h, w
        (scale1, bias1), dlogdet1 = self.affineParams(affine_input, forward_mode=False)
        x0, x1, x2 = z0, (z1-bias1)/scale1, z2
        inputs = outputs[:self.start_idx]+(x0, x1, x2)+outputs[self.start_idx+3:]
        in_logdets = logdets[:self.start_idx]+(logdet0, logdet1-dlogdet1, logdet2)+logdets[self.start_idx+3:]
        return inputs, in_logdets
//  [python]
def sem_seg_postprocess(self, result, img_size, output_height,
                            output_width):
        result = result[:, :img_size[0], :img_size[1]].expand(1, -1, -1, -1)
        result = t.nn.functional.interpolate(
            result,
            size=(output_height, output_width),
            mode='bilinear',
            align_corners=False)[0]
        return result
//  [python]
def sem_seg_postprocess(self, result, img_size, output_height,
                            output_width):
        result = result[:, :img_size[0], :img_size[1]].expand(1, -1, -1, -1)
        result = F.interpolate(
            result,
            size=(output_height, output_width),
            mode='bilinear',
            align_corners=False)[0]
        return result
//  [python]
def forward(self, x, feature_alignment=False):

        input_spatial_dim = x.size()[2:]

        if feature_alignment:

            x = adjust_input_image_size_for_proper_feature_alignment(x, output_stride=8)

        x = self.resnet18_8s(x)

        #Newer method, upsample deprecated.
        #x = nn.functional.interpolate(x, size=input_spatial_dim, mode='bilinear', align_corners=True)
        #orig
        x = nn.functional.upsample(x, size=input_spatial_dim, mode='bilinear', align_corners=True)

        return x
//  [python]
def forward(self, x, feature_alignment=False):

        input_spatial_dim = x.size()[2:]

        if feature_alignment:

            x = adjust_input_image_size_for_proper_feature_alignment(x, output_stride=8)

        x = self.resnet18_8s(x)

        #Newer method, upsample deprecated.
        x = nn.functional.interpolate(x, size=input_spatial_dim, mode='bilinear', align_corners=True)
        #orig
        #x = nn.functional.upsample(x, size=input_spatial_dim, mode='bilinear', align_corners=True)

        return x
//  [python]
def single_human_sem_seg_postprocess(self, result, img_size, crop_box,
                                         output_height, output_width):
        result = result[:, :img_size[0], :img_size[1]]
        result = result[:, crop_box[1]:crop_box[3],
                        crop_box[0]:crop_box[2]].expand(1, -1, -1, -1)
        result = t.nn.functional.interpolate(
            result,
            size=(output_height, output_width),
            mode='bilinear',
            align_corners=False)[0]
        return result
//  [python]
def single_human_sem_seg_postprocess(self, result, img_size, crop_box,
                                         output_height, output_width):
        result = result[:, :img_size[0], :img_size[1]]
        result = result[:, crop_box[1]:crop_box[3],
                        crop_box[0]:crop_box[2]].expand(1, -1, -1, -1)
        result = F.interpolate(
            result,
            size=(output_height, output_width),
            mode='bilinear',
            align_corners=False)[0]
        return result
//  [python]
def forward(self, feats):
        h, w = feats.size(2), feats.size(3)
        priors = [
            t.interpolate(
                input=self.act(stage(feats)),
                size=(h, w),
                mode='bilinear',
                align_corners=False) for stage in self.stages
        ] + [feats]
        out = self.act(self.bottleneck(torch.cat(priors, 1)))
        return out
//  [python]
def forward(self, feats):
        h, w = feats.size(2), feats.size(3)
        priors = [
            F.interpolate(
                input=self.act(stage(feats)),
                size=(h, w),
                mode='bilinear',
                align_corners=False) for stage in self.stages
        ] + [feats]
        out = self.act(self.bottleneck(torch.cat(priors, 1)))
        return out
//  [python]
def forward(self, x, y, w):
        x = t.interpolate(x, size=16)
        x = t.interpolate(x, scale_factor=2, mode='nearest')
        x = t.interpolate(x, size=(20), mode='nearest')
        x = t.interpolate(x, scale_factor=(4), mode='nearest')
        x = t.interpolate(x, size=16, mode='linear')
        x = t.interpolate(x, scale_factor=2, mode='linear')
        x = t.interpolate(x, size=(24), mode='linear', align_corners=True)
        x = t.interpolate(x, scale_factor=(3), mode='linear', align_corners=True)

        x = t.interpolate(x, scale_factor=1.5, mode='nearest', recompute_scale_factor=True)
        x = t.interpolate(x, scale_factor=1.2, mode='linear', align_corners=False, recompute_scale_factor=True)
        x = t.interpolate(x, scale_factor=0.8, mode='linear', align_corners=True, recompute_scale_factor=True)

        y = t.interpolate(y, size=16)
        y = t.interpolate(y, scale_factor=2, mode='nearest')
        y = t.interpolate(y, size=(20,20), mode='nearest')
        y = t.interpolate(y, scale_factor=(4,4), mode='nearest')
        y = t.interpolate(y, size=(16,24), mode='nearest')
        y = t.interpolate(y, scale_factor=(2,3), mode='nearest')
        y = t.interpolate(y, size=16, mode='bilinear')
        y = t.interpolate(y, scale_factor=2, mode='bilinear')
        y = t.interpolate(y, size=(20,20), mode='bilinear', align_corners=False)
        y = t.interpolate(y, scale_factor=(4,4), mode='bilinear', align_corners=False)
        y = t.interpolate(y, size=(16,24), mode='bilinear', align_corners=True)
        y = t.interpolate(y, scale_factor=(2,3), mode='bilinear', align_corners=True)
        y = t.interpolate(y, size=16, mode='bicubic')
        y = t.interpolate(y, scale_factor=2, mode='bicubic')
        y = t.interpolate(y, size=(20,20), mode='bicubic', align_corners=False)
        y = t.interpolate(y, scale_factor=(4,4), mode='bicubic', align_corners=False)
        y = t.interpolate(y, size=(16,24), mode='bicubic', align_corners=True)
        y = t.interpolate(y, scale_factor=(2,3), mode='bicubic', align_corners=True)

        y = t.interpolate(y, scale_factor=(1.6,2), mode='nearest', recompute_scale_factor=True)
        y = t.interpolate(y, scale_factor=(2,1.2), mode='bilinear', align_corners=False, recompute_scale_factor=True)
        y = t.interpolate(y, scale_factor=(0.5,0.4), mode='bilinear', align_corners=True, recompute_scale_factor=True)
        y = t.interpolate(y, scale_factor=(0.8,0.9), mode='bicubic', align_corners=False, recompute_scale_factor=True)
        y = t.interpolate(y, scale_factor=(1.1,0.5), mode='bicubic', align_corners=True, recompute_scale_factor=True)

        w = t.interpolate(w, scale_factor=(2.976744,2.976744), mode='nearest', recompute_scale_factor=False)
        return x, y, w
//  [python]
def forward(self, x, y, w):
        x = F.interpolate(x, size=16)
        x = F.interpolate(x, scale_factor=2, mode='nearest')
        x = F.interpolate(x, size=(20), mode='nearest')
        x = F.interpolate(x, scale_factor=(4), mode='nearest')
        x = F.interpolate(x, size=16, mode='linear')
        x = F.interpolate(x, scale_factor=2, mode='linear')
        x = F.interpolate(x, size=(24), mode='linear', align_corners=True)
        x = F.interpolate(x, scale_factor=(3), mode='linear', align_corners=True)

        x = F.interpolate(x, scale_factor=1.5, mode='nearest', recompute_scale_factor=True)
        x = F.interpolate(x, scale_factor=1.2, mode='linear', align_corners=False, recompute_scale_factor=True)
        x = F.interpolate(x, scale_factor=0.8, mode='linear', align_corners=True, recompute_scale_factor=True)

        y = F.interpolate(y, size=16)
        y = F.interpolate(y, scale_factor=2, mode='nearest')
        y = F.interpolate(y, size=(20,20), mode='nearest')
        y = F.interpolate(y, scale_factor=(4,4), mode='nearest')
        y = F.interpolate(y, size=(16,24), mode='nearest')
        y = F.interpolate(y, scale_factor=(2,3), mode='nearest')
        y = F.interpolate(y, size=16, mode='bilinear')
        y = F.interpolate(y, scale_factor=2, mode='bilinear')
        y = F.interpolate(y, size=(20,20), mode='bilinear', align_corners=False)
        y = F.interpolate(y, scale_factor=(4,4), mode='bilinear', align_corners=False)
        y = F.interpolate(y, size=(16,24), mode='bilinear', align_corners=True)
        y = F.interpolate(y, scale_factor=(2,3), mode='bilinear', align_corners=True)
        y = F.interpolate(y, size=16, mode='bicubic')
        y = F.interpolate(y, scale_factor=2, mode='bicubic')
        y = F.interpolate(y, size=(20,20), mode='bicubic', align_corners=False)
        y = F.interpolate(y, scale_factor=(4,4), mode='bicubic', align_corners=False)
        y = F.interpolate(y, size=(16,24), mode='bicubic', align_corners=True)
        y = F.interpolate(y, scale_factor=(2,3), mode='bicubic', align_corners=True)

        y = F.interpolate(y, scale_factor=(1.6,2), mode='nearest', recompute_scale_factor=True)
        y = F.interpolate(y, scale_factor=(2,1.2), mode='bilinear', align_corners=False, recompute_scale_factor=True)
        y = F.interpolate(y, scale_factor=(0.5,0.4), mode='bilinear', align_corners=True, recompute_scale_factor=True)
        y = F.interpolate(y, scale_factor=(0.8,0.9), mode='bicubic', align_corners=False, recompute_scale_factor=True)
        y = F.interpolate(y, scale_factor=(1.1,0.5), mode='bicubic', align_corners=True, recompute_scale_factor=True)

        w = F.interpolate(w, scale_factor=(2.976744,2.976744), mode='nearest', recompute_scale_factor=False)
        return x, y, w
//  [python]
def adjust_input_image_size_for_proper_feature_alignment(input_img_batch, output_stride=8):
    """Resizes the input image to allow proper feature alignment during the
    forward propagation.

    Resizes the input image to a closest multiple of `output_stride` + 1.
    This allows the proper alignment of features.
    To get more details, read here:
    https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py#L159

    Parameters
    ----------
    input_img_batch : torch.Tensor
        Tensor containing a single input image of size (1, 3, h, w)

    output_stride : int
        Output stride of the network where the input image batch
        will be fed.

    Returns
    -------
    input_img_batch_new_size : torch.Tensor
        Resized input image batch tensor
    """

    input_spatial_dims = np.asarray( input_img_batch.shape[2:], dtype=np.float )

    # Comments about proper alignment can be found here
    # https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py#L159
    new_spatial_dims = np.ceil(input_spatial_dims / output_stride).astype(np.int) * output_stride + 1

    # Converting the numpy to list, torch.nn.functional.upsample_bilinear accepts
    # size in the list representation.
    new_spatial_dims = list(new_spatial_dims)

    #input_img_batch_new_size = nn.functional.upsample_bilinear(input=input_img_batch, size=new_spatial_dims)
    input_img_batch_new_size = nn.functional.upsample_bilinear(input=input_img_batch, size=new_spatial_dims)

    return input_img_batch_new_size
//  [python]
def adjust_input_image_size_for_proper_feature_alignment(input_img_batch, output_stride=8):
    """Resizes the input image to allow proper feature alignment during the
    forward propagation.

    Resizes the input image to a closest multiple of `output_stride` + 1.
    This allows the proper alignment of features.
    To get more details, read here:
    https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py#L159

    Parameters
    ----------
    input_img_batch : torch.Tensor
        Tensor containing a single input image of size (1, 3, h, w)

    output_stride : int
        Output stride of the network where the input image batch
        will be fed.

    Returns
    -------
    input_img_batch_new_size : torch.Tensor
        Resized input image batch tensor
    """

    input_spatial_dims = np.asarray( input_img_batch.shape[2:], dtype=np.float )

    # Comments about proper alignment can be found here
    # https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py#L159
    new_spatial_dims = np.ceil(input_spatial_dims / output_stride).astype(np.int) * output_stride + 1

    # Converting the numpy to list, torch.nn.functional.upsample_bilinear accepts
    # size in the list representation.
    new_spatial_dims = list(new_spatial_dims)

    #input_img_batch_new_size = nn.functional.upsample_bilinear(input=input_img_batch, size=new_spatial_dims)
    input_img_batch_new_size = nn.functional.interpolate(input=input_img_batch, size=new_spatial_dims,
                                                         mode='bilinear', align_corners=True)

    return input_img_batch_new_size
//  [python]
def forward(self, q_input, scale_factor: float, mode: str):
        return torch.nn.functional.upsample(
            q_input, scale_factor=scale_factor, mode=mode
        )
//  [python]
def forward(self, q_input, scale_factor: float, mode: str):
        return torch.nn.functional.interpolate(
            q_input, scale_factor=scale_factor, mode=mode
        )