コード例 #1
0
ファイル: defconv.py プロジェクト: Ayagoz/DefConv_module
    def identity_mapping(self, shape, normalize=True):
        grid = np.mgrid[tuple(map(slice, shape))].astype('float32')

        if normalize:
            grid = grid / (np.array(shape) - 1).reshape((-1,) + (1,) * len(shape))
            grid = 2 * grid - 1

        return to_var(grid, is_on_cuda(self)).float()
コード例 #2
0
    def z_to_curve(self, z, input):
        self.model_core.eval()

        with torch.no_grad():
            input_shape = input.shape
            batch_size = input_shape[0]
            z = to_var(z, self.model_core)
            x = self.autoencoder.decoder_lin(z)
            x = x.reshape(batch_size, 128, 32)
            x = self.autoencoder.decoder_conv(x)
            reproduced_curve = nn.functional.interpolate(x, input_shape[2:])
            return to_np(reproduced_curve)
コード例 #3
0
    def do_inf_step(self, batch_of_images):
        """
        Returns the prediction for the given ``inputs``.

        Notes
        -----
        Note that both input and output are **not** of type `torch.Tensor` - the conversion
        to torch.Tensor is made inside this function.
        """
        self.model_core.eval()

        with torch.no_grad():
            batch_of_images = to_var(batch_of_images, self.model_core)
            u_out = self.u_net(batch_of_images)
            return to_np(self.logits2pred(u_out))
コード例 #4
0
    def get_trio(self, batch_of_images):
        """
        Returns the prediction for the given ``inputs``.

        Notes
        -----
        Note that both input and output are **not** of type `torch.Tensor` - the conversion
        to torch.Tensor is made inside this function.
        """
        self.model_core.eval()

        with torch.no_grad():
            batch_of_images = to_var(batch_of_images, self.model_core)
            u_out = self.u_net(batch_of_images)
            u_curve = self.to_curve(u_out)
            z, reconstructed = self.autoencoder(u_curve)
            return to_np(
                self.logits2pred(u_out)), to_np(z), to_np(reconstructed)