GAN_CIFAR10_tf module

class GAN_CIFAR10_tf.Discriminator(*args, **kwargs)[source]

Bases: Model

Discriminator model, which evaluates whether inputs are real or fake.

call()[source]

Passes input images through the discriminator network.

build(input_shape)[source]

Build the discriminator. :param input_shape: The shape of the input tensor.

call(inputs, training=True)[source]

Forward pass of the discriminator. :param inputs: Input images. :type inputs: tf.Tensor :param training: Whether the model is training. :type training: bool

Returns:

Discriminator score for each image.

Return type:

tf.Tensor

class GAN_CIFAR10_tf.DiscriminatorBlock(*args, **kwargs)[source]

Bases: Layer

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.

call()[source]

Passes input through the discriminator block.

build(input_shape)[source]

Build the layer. :param input_shape: The shape of the input tensor.

call(inputs, training=False)[source]

Forward pass of the discriminator block. :param inputs: Input tensor. :type inputs: tf.Tensor

Returns:

Output tensor after passing through the block.

Return type:

tf.Tensor

class GAN_CIFAR10_tf.Generator(*args, **kwargs)[source]

Bases: Model

Generator model that consists of a dense layer followed by multiple generator blocks.

call()[source]

Passes input latent vectors through the generator network.

build(input_shape)[source]

Build the generator. :param input_shape: The shape of the input tensor.

call(noise, training=True)[source]

Forward pass of the generator. :param noise: Latent vectors. :type noise: tf.Tensor :param training: If the model is training. :type training: bool

Returns:

Generated image tensor.

Return type:

tf.Tensor

class GAN_CIFAR10_tf.GeneratorBlock(*args, **kwargs)[source]

Bases: Layer

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.

call()[source]

Passes input through the generator block.

build(input_shape)[source]

Build the layer. :param input_shape: The shape of the input tensor.

call(inputs)[source]

Forward pass of the generator block.

Parameters:

inputs (tf.Tensor) – Input tensor.

Returns:

Output tensor after passing through the block.

Return type:

tf.Tensor

compute_output_shape(input_shape)[source]

Compute output shape of the block. :param input_shape: The shape of the input tensor.

Returns:

Tuple of the output shape.

classmethod from_config(config)[source]

Instantiate the block from a configuration. :param config: Configuration dictionary.

Returns:

An instance of GeneratorBlock.

Return type:

GeneratorBlock

get_config()[source]

Get the configuration of the block for serialization. :returns: Configuration dictionary. :rtype: dict

GAN_CIFAR10_tf.avg_pool2d(x)[source]

Implements a twice-differentiable 2x2 average pooling operation.

Parameters:

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

Returns:

Averaged pooled tensor.

Return type:

tf.Tensor