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

Method __init__

draggan/stylegan2/training/networks.py:365–414  ·  view source on GitHub ↗
(self,
        in_channels,                            # Number of input channels, 0 = first block.
        out_channels,                           # Number of output channels.
        w_dim,                                  # Intermediate latent (W) dimensionality.
        resolution,                             # Resolution of this block.
        img_channels,                           # Number of output color channels.
        is_last,                                # Is this the last block?
        architecture            = 'skip',       # Architecture: 'orig', 'skip', 'resnet'.
        resample_filter         = [1,3,3,1],    # Low-pass filter to apply when resampling activations.
        conv_clamp              = 256,          # Clamp the output of convolution layers to +-X, None = disable clamping.
        use_fp16                = False,        # Use FP16 for this block?
        fp16_channels_last      = False,        # Use channels-last memory format with FP16?
        fused_modconv_default   = True,         # Default value of fused_modconv. 'inference_only' = True for inference, False for training.
        **layer_kwargs,                         # Arguments for SynthesisLayer.
    )

Source from the content-addressed store, hash-verified

363@persistence.persistent_class
364class SynthesisBlock(torch.nn.Module):
365 def __init__(self,
366 in_channels, # Number of input channels, 0 = first block.
367 out_channels, # Number of output channels.
368 w_dim, # Intermediate latent (W) dimensionality.
369 resolution, # Resolution of this block.
370 img_channels, # Number of output color channels.
371 is_last, # Is this the last block?
372 architecture = 'skip', # Architecture: 'orig', 'skip', 'resnet'.
373 resample_filter = [1,3,3,1], # Low-pass filter to apply when resampling activations.
374 conv_clamp = 256, # Clamp the output of convolution layers to +-X, None = disable clamping.
375 use_fp16 = False, # Use FP16 for this block?
376 fp16_channels_last = False, # Use channels-last memory format with FP16?
377 fused_modconv_default = True, # Default value of fused_modconv. 'inference_only' = True for inference, False for training.
378 **layer_kwargs, # Arguments for SynthesisLayer.
379 ):
380 assert architecture in ['orig', 'skip', 'resnet']
381 super().__init__()
382 self.in_channels = in_channels
383 self.w_dim = w_dim
384 self.resolution = resolution
385 self.img_channels = img_channels
386 self.is_last = is_last
387 self.architecture = architecture
388 self.use_fp16 = use_fp16
389 self.channels_last = (use_fp16 and fp16_channels_last)
390 self.fused_modconv_default = fused_modconv_default
391 self.register_buffer('resample_filter', upfirdn2d.setup_filter(resample_filter))
392 self.num_conv = 0
393 self.num_torgb = 0
394
395 if in_channels == 0:
396 self.const = torch.nn.Parameter(torch.randn([out_channels, resolution, resolution]))
397
398 if in_channels != 0:
399 self.conv0 = SynthesisLayer(in_channels, out_channels, w_dim=w_dim, resolution=resolution, up=2,
400 resample_filter=resample_filter, conv_clamp=conv_clamp, channels_last=self.channels_last, **layer_kwargs)
401 self.num_conv += 1
402
403 self.conv1 = SynthesisLayer(out_channels, out_channels, w_dim=w_dim, resolution=resolution,
404 conv_clamp=conv_clamp, channels_last=self.channels_last, **layer_kwargs)
405 self.num_conv += 1
406
407 if is_last or architecture == 'skip':
408 self.torgb = ToRGBLayer(out_channels, img_channels, w_dim=w_dim,
409 conv_clamp=conv_clamp, channels_last=self.channels_last)
410 self.num_torgb += 1
411
412 if in_channels != 0 and architecture == 'resnet':
413 self.skip = Conv2dLayer(in_channels, out_channels, kernel_size=1, bias=False, up=2,
414 resample_filter=resample_filter, channels_last=self.channels_last)
415
416 def forward(self, x, img, ws, force_fp32=False, fused_modconv=None, update_emas=False, **layer_kwargs):
417 _ = update_emas # unused

Callers

nothing calls this directly

Calls 4

ToRGBLayerClass · 0.85
Conv2dLayerClass · 0.85
SynthesisLayerClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected