def generate_sample_image()

in torchrecipes/vision/image_generation/module/infogan.py [0:0]


    def generate_sample_image(self, n_row: int = 10) -> Tensor:
        # Static sample
        z = torch.tensor(
            np.random.normal(0, 1, (n_row ** 2, self.latent_dim)),
            dtype=torch.float,
            device=self.device,
        )

        static_sample = self.generator(z, self.static_label, self.static_code)
        static_img = make_grid(static_sample, nrow=n_row, normalize=True, padding=0)

        # Get varied c1 and c2
        zeros = np.zeros((n_row ** 2, 1))
        c_varied = np.repeat(np.linspace(-1, 1, n_row)[:, np.newaxis], n_row, 0)
        c1 = torch.tensor(
            np.concatenate((c_varied, zeros), -1),
            dtype=torch.float,
            device=self.device,
        )
        c2 = torch.tensor(
            np.concatenate((zeros, c_varied), -1),
            dtype=torch.float,
            device=self.device,
        )
        sample1 = self.generator(self.static_z, self.static_label, c1)
        sample1_img = make_grid(sample1, nrow=n_row, normalize=True, padding=0)
        sample2 = self.generator(self.static_z, self.static_label, c2)
        sample2_img = make_grid(sample2, nrow=n_row, normalize=True, padding=0)

        return torch.cat((static_img, sample1_img, sample2_img), 0)