code: def get_image_gan_tf_v2():
      import tensorflow as tf  # lgtm [py/import-and-import-from]
  
      noise_dim = 100
      capacity = 64
      generator = get_image_generator_tf_v2(capacity, noise_dim)
  
      def make_image_discriminator_model(
          capacity: int,
      ) -> tf.keras.Sequential():
          model = tf.keras.Sequential()
  
          model.add(
              tf.keras.layers.Conv2D(
                  capacity,
                  (5, 5),
                  strides=(2, 2),
                  padding="same",
                  input_shape=[28, 28, 1],
              )
          )
          model.add(tf.keras.layers.LeakyReLU())
          model.add(tf.keras.layers.Dropout(0.3))
  
          model.add(
              tf.keras.layers.Conv2D(
                  capacity * 2, (5, 5), strides=(2, 2), padding="same"
              )
          )
          model.add(tf.keras.layers.LeakyReLU())
          model.add(tf.keras.layers.Dropout(0.3))
  
          model.add(tf.keras.layers.Flatten())
          model.add(tf.keras.layers.Dense(1))
  
          return model
  
      discriminator_classifier = TensorFlowV2Classifier(
          model=make_image_discriminator_model(capacity),
          nb_classes=2,
          input_shape=(28, 28, 28, 1),
      )
  
      def generator_orig_loss_fct(generated_output):
          return tf.compat.v1.losses.sigmoid_cross_entropy(
              tf.ones_like(generated_output), generated_output
          )
  
      def discriminator_loss_fct(real_output, generated_output):
          """Discriminator loss
  
          The discriminator loss function takes two inputs: real images, and generated images. Here is how to calculate
          the discriminator loss:
          1. Calculate real_loss which is a sigmoid cross entropy loss of the real images and an array of ones (since
          these are the real images).
          2. Calculate generated_loss which is a sigmoid cross entropy loss of the generated images and an array of
          zeros (since these are the fake images).
          3. Calculate the total_loss as the sum of real_loss and generated_loss.
          """
          # [1,1,...,1] with real output since it is true and we want our generated examples to look like it
          real_loss = tf.compat.v1.losses.sigmoid_cross_entropy(
              multi_class_labels=tf.ones_like(real_output),
              logits=real_output,
          )
  
          # [0,0,...,0] with generated images since they are fake
          generated_loss = tf.compat.v1.losses.sigmoid_cross_entropy(
              multi_class_labels=tf.zeros_like(generated_output),
              logits=generated_output,
          )
  
          total_loss = real_loss + generated_loss
  
          return total_loss
  
      gan = TensorFlowV2GAN(
          generator=generator,
          discriminator=discriminator_classifier,
          generator_loss=generator_orig_loss_fct,
          generator_optimizer_fct=tf.compat.v1.train.AdamOptimizer(
              1e-4
          ),
          discriminator_loss=discriminator_loss_fct,
          discriminator_optimizer_fct=tf.compat.v1.train.AdamOptimizer(
              1e-4
          ),
      )
      return gan
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import json
  import logging
  import os
  import pickle
  import time
  import unittest
  import warnings
  import sklearn
  import numpy
  from art.estimators.classification.tensorflow import TensorFlowV2Classifier
  from art.estimators.encoding.tensorflow import TensorFlowEncoder
  from art.estimators.generation.tensorflow import TensorFlowGenerator, TensorFlowV2Generator
  from art.estimators.gan.tensorflow import TensorFlowV2GAN
  from art.utils import load_dataset
label_desc: Use image node_id 10 for calling a global function with example usage: get_image_gan_tf_v2() and returns: gan, model, tf, total_loss