Forward pass through the generator network. Args: G (torch.nn.Module): The generator network. W (torch.Tensor): The latent code tensor of shape [batch_size, latent_dim, 512]. device (torch.device): The device to use for the computation. Returns: A tuple
(
G: torch.nn.Module,
W: torch.Tensor,
device: torch.device,
)
| 114 | |
| 115 | |
| 116 | def forward_G( |
| 117 | G: torch.nn.Module, |
| 118 | W: torch.Tensor, |
| 119 | device: torch.device, |
| 120 | ) -> Tuple[torch.Tensor, torch.Tensor]: |
| 121 | """ |
| 122 | Forward pass through the generator network. |
| 123 | |
| 124 | Args: |
| 125 | G (torch.nn.Module): The generator network. |
| 126 | W (torch.Tensor): The latent code tensor of shape [batch_size, latent_dim, 512]. |
| 127 | device (torch.device): The device to use for the computation. |
| 128 | |
| 129 | Returns: |
| 130 | A tuple containing the generated image tensor of shape [batch_size, 3, height, width] |
| 131 | and the feature maps tensor of shape [batch_size, num_channels, height, width]. |
| 132 | """ |
| 133 | register_hook(G) |
| 134 | |
| 135 | if not isinstance(W, torch.Tensor): |
| 136 | W = torch.from_numpy(W).to(device) |
| 137 | |
| 138 | img = G.synthesis(W, noise_mode="const", force_fp32=True) |
| 139 | |
| 140 | return img, G.activations[0] |
| 141 | |
| 142 | |
| 143 | def generate_image( |
no test coverage detected