title: How to use TensorFlow Dataset API in GANs training?
body: <p>I am training GANs model. For loading the dataset, I am using Dataset API of TensorFlow.</p>
  
  <pre><code># train_dataset has image and label. z_train dataset has noise (z).
  train_dataset = tf.data.TFRecordDataset(train_file)
  z_train = tf.data.Dataset.from_tensor_slices(tf.random_uniform([total_training_samples, seq_length,  z_dim],
                                                                   minval=0, maxval=1, dtype=tf.float32))
  
  train_dataset = tf.data.Dataset.zip((train_dataset, z_train))
  </code></pre>
  
  <p>Creating Iterator:</p>
  
  <pre><code>iter = tf.data.Iterator.from_structure(train_dataset.output_types, train_dataset.output_shapes)
  </code></pre>
  
  <p>Using the iterator:</p>
  
  <pre><code>(img, label), z = iter.get_next()
  train_init_op = iter.make_initializer(train_dataset)
  </code></pre>
  
  <p>While training the GAN in session:<br>
  Training Discriminator first:</p>
  
  <pre><code>_, disc_loss = sess.run([disc_optim, disc_loss])
  </code></pre>
  
  <p>then training Generator:</p>
  
  <pre><code>_, gen_loss = sess.run([gen_optim, gen_loss])
  </code></pre>
  
  <p>Here is the catch. Since, I am using <strong>label</strong> as condition (CGAN) in both, discriminator and generator graph, using two sess.run produces two different set of batch of <strong>label</strong> during the same run of batch.</p>
  
  <pre><code>for epoch in range(num_of_epochs):
      sess.run([tf.global_variables_initializer(), train_init_op.initializer])
      for batch in range(num_of_batches):
          _, disc_loss = sess.run([disc_optim, disc_loss])
          _, gen_loss = sess.run([gen_optim, gen_loss])
  </code></pre>
  
  <p>Since, I have to feed the same batch of <strong>label</strong> in the generator's session run as in discriminator's session run, how shall I prevent Dataset API to produce two different batches in the same loop of a batch?
  <br>Note: I am using TensorFlow v1.9
  <br>Thanks in advance.</p>