MCPcopy Create free account
hub / github.com/OpenGVLab/DragGAN / forward_G

Function forward_G

draggan/draggan.py:116–140  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

114
115
116def 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
143def generate_image(

Callers 2

generate_imageFunction · 0.85
drag_ganFunction · 0.85

Calls 1

register_hookFunction · 0.85

Tested by

no test coverage detected