GAN_CIFAR10_torch module

class GAN_CIFAR10_torch.Discriminator[source]

Bases: Module

Discriminator (or critic) model for GAN.

forward()[source]

Passes input images through the discriminator.

forward(*inputs, labels=None)[source]

Forward pass of the discriminator.

Parameters:

inputs (torch.Tensor) – Input image tensor.

Returns:

Scalar score for each image.

Return type:

torch.Tensor

class GAN_CIFAR10_torch.DiscriminatorBlock(in_chans, out_chans, downsample=False, first=False)[source]

Bases: Module

ResNet-style block for the discriminator model, with optional downsampling.

Parameters:
  • in_chans (int) – Number of input channels.

  • out_chans (int) – Number of output channels.

  • downsample (bool) – Whether to apply 2x downsampling.

  • first (bool) – Whether this is the first block in the discriminator.

forward()[source]

Passes input through the discriminator block.

forward(*inputs)[source]

Forward pass of the discriminator block.

Parameters:

inputs (torch.Tensor) – Input tensor.

Returns:

Output tensor after passing through the block.

Return type:

torch.Tensor

class GAN_CIFAR10_torch.Discriminator_cond[source]

Bases: Module

Conditional Discriminator (or critic) model for conditional GAN.

forward()[source]

Passes input images and labels through the discriminator.

forward(x, labels)[source]

Forward pass of the conditional discriminator.

Parameters:
  • x (torch.Tensor) – Input image tensor.

  • labels (torch.Tensor) – One-hot encoded labels.

Returns:

Scalar score for each image.

Return type:

torch.Tensor

class GAN_CIFAR10_torch.Generator[source]

Bases: Module

Generator model that consists of linear layers followed by multiple generator blocks.

forward()[source]

Passes input latent vectors through the generator network.

forward(*inputs, labels=None)[source]

Forward pass of the generator.

Parameters:
  • inputs (torch.Tensor) – Latent vectors.

  • labels (torch.Tensor) – (Optional) Labels, if required.

Returns:

Generated image tensor.

Return type:

torch.Tensor

class GAN_CIFAR10_torch.GeneratorBlock(in_chans, out_chans, upsample=False)[source]

Bases: Module

ResNet-style block for the generator model, with optional upsampling.

Parameters:
  • in_chans (int) – Number of input channels.

  • out_chans (int) – Number of output channels.

  • upsample (bool) – Whether to apply 2x upsampling.

forward()[source]

Passes input through the generator block.

forward(*inputs)[source]

Forward pass of the generator block.

Parameters:

inputs (torch.Tensor) – Input tensor.

Returns:

Output tensor after passing through the block.

Return type:

torch.Tensor

class GAN_CIFAR10_torch.Generator_cond[source]

Bases: Module

Conditional Generator model for conditional GAN.

forward()[source]

Passes input latent vectors and labels through the generator.

forward(z, labels)[source]

Forward pass of the conditional generator.

Parameters:
  • z (torch.Tensor) – Latent vectors.

  • labels (torch.Tensor) – One-hot encoded labels.

Returns:

Generated image tensor.

Return type:

torch.Tensor

GAN_CIFAR10_torch.avg_pool2d(x)[source]

Implements a twice-differentiable 2x2 average pooling operation.

Parameters:

x (torch.Tensor) – Input tensor of shape (batch_size, channels, height, width).

Returns:

Averaged pooled tensor.

Return type:

torch.Tensor