code: def create_synthesis_network(
      latent_code_dimension: int = 128,
      upsampling_blocks_num_channels: Sequence[int] = (
          512,
          256,
          128,
          64,
      ),
      relu_leakiness: float = 0.2,
      use_bilinear_upsampling: bool = True,
      use_noise_inputs: bool = False,
      name: str = "synthesis",
  ):
      """Creates the synthesis network using the functional API.
  
      The function creates the synthesis network as defined in "Analyzing and
      Improving the Image Quality of StyleGAN" https://arxiv.org/pdf/1912.04958.pdf
      using the Keras functional API.
  
      Args:
        latent_code_dimension: The number of dimensions in the latent code.
        upsampling_blocks_num_channels: The number of channels for each upsampling
          block. This argument also determines how many upsampling blocks are added.
        relu_leakiness: Slope of the negative part of the leaky relu.
        use_bilinear_upsampling: If true bilinear upsampling is used.
        use_noise_inputs: If the model takes noise as input, if false noise is
          sampled randomly.
        name: The name of the Keras model.
  
      Returns:
        The synthesis network.
      """
      kernel_initializer = tf.keras.initializers.TruncatedNormal(
          mean=0.0, stddev=1.0
      )
      mapped_latent_code_input = tf.keras.Input(
          shape=(latent_code_dimension,)
      )
  
      if use_noise_inputs:
          noise_inputs = _create_noise_inputs(
              len(upsampling_blocks_num_channels)
          )
  
      tensor = keras_layers.LearnedConstant()(mapped_latent_code_input)
      tensor = keras_layers.DemodulatedConvolution(
          filters=upsampling_blocks_num_channels[0], kernel_size=3
      )((tensor, mapped_latent_code_input))
      if use_noise_inputs:
          tensor = keras_layers.Noise()((tensor, noise_inputs[0]))
      else:
          tensor = keras_layers.Noise()(tensor)
      tensor = tf.keras.layers.LeakyReLU(alpha=relu_leakiness)(tensor)
  
      output = None
      for index, channels in enumerate(upsampling_blocks_num_channels):
          output = _maybe_upsample_and_add_outputs(
              architectures_progressive_gan.to_rgb(
                  input_tensor=tensor,
                  kernel_initializer=kernel_initializer,
                  name="side_output_%d_conv" % index,
              ),
              output,
              use_bilinear_upsampling=use_bilinear_upsampling,
          )
          tensor = keras_layers.TwoByTwoNearestNeighborUpSampling()(
              tensor
          )
          if use_bilinear_upsampling:
              tensor = keras_layers.Blur2D()(tensor)
          for inner_index in range(2):
              tensor = keras_layers.DemodulatedConvolution(
                  filters=channels, kernel_size=3
              )((tensor, mapped_latent_code_input))
              if use_noise_inputs:
                  noise_index = 2 * index + inner_index + 1
                  tensor = keras_layers.Noise()(
                      (tensor, noise_inputs[noise_index])
                  )
              else:
                  tensor = keras_layers.Noise()(tensor)
              tensor = tf.keras.layers.LeakyReLU(alpha=relu_leakiness)(
                  tensor
              )
  
      output = _maybe_upsample_and_add_outputs(
          architectures_progressive_gan.to_rgb(
              input_tensor=tensor, kernel_initializer=kernel_initializer
          ),
          output,
          use_bilinear_upsampling=use_bilinear_upsampling,
      )
  
      if use_noise_inputs:
          inputs = [mapped_latent_code_input] + noise_inputs
      else:
          inputs = mapped_latent_code_input
  
      return tf.keras.Model(inputs=inputs, outputs=output, name=name)
  
file_path: graphics/tensorflow_graphics/projects/gan/architectures_style_gan_v2.py
imports: import math
  from typing import Callable, List, Optional, Sequence, Tuple, Union
  import tensorflow
  from tensorflow_graphics.projects.gan import architectures_progressive_gan
  from tensorflow_graphics.projects.gan import architectures_style_gan
  from tensorflow_graphics.projects.gan import keras_layers
label_desc: Use image node_id 4 for calling a global function with example usage: create_synthesis_network(latent_code_dimension, upsampling_blocks_num_channels, relu_leakiness, use_bilinear_upsampling, use_noise_inputs, name) and returns: tf