title: How to load data during training of a multi-output model without iteration in Keras?
body: <p>I have a Keras model with 1 input and 2 outputs in TensorFlow 2. When calling <code>model.fit</code> I want to pass dataset as <code>x=train_dataset</code> and call <code>model.fit</code> once. The <code>train_dataset</code> is made with <code>tf.data.Dataset.from_generator</code> which yields: x1, y1, y2.</p>
  
  <p>The only way I can run training is the following:</p>
  
  <pre><code>for x1, y1,y2 in train_dataset:
      model.fit(x=x1, y=[y1,y2],...)
  </code></pre>
  
  <p>How to tell TensorFlow to unpack variables and train without the explicit <code>for</code> loop? Using the <code>for</code> loop makes many things less practical, as well as usage of <code>train_on_batch</code>.</p>
  
  <p>If I want to run <code>model.fit(train_dataset, ...)</code> the function doesn't understand what <code>x</code> and <code>y</code> are, even the model is defined like:</p>
  
  <pre><code>model = Model(name ='Joined_Model',inputs=self.x, outputs=[self.network.y1, self.network.y2])
  </code></pre>
  
  <p>It throws an error that it is expecting 2 targets while getting 1, even the dataset has 3 variables, which can be iterated trough in the loop.</p>
  
  <p>The dataset and mini-batch are generated as:</p>
  
  <pre><code>def dataset_joined(self, n_epochs, buffer_size=32):
      dataset = tf.data.Dataset.from_generator(
          self.mbatch_gen_joined,
          (tf.float32, tf.float32,tf.int32),
          (tf.TensorShape([None, None, self.n_feat]),
              tf.TensorShape([None, None, self.n_feat]),
              tf.TensorShape([None, None])),
          [tf.constant(n_epochs)]
          )
      dataset = dataset.prefetch(buffer_size)
      return dataset
  
      def mbatch_gen_joined(self, n_epochs):
      for _ in range(n_epochs):
          random.shuffle(self.train_s_list)
          start_idx, end_idx = 0, self.mbatch_size
          for _ in range(self.n_iter):
              s_mbatch_list = self.train_s_list[start_idx:end_idx]
              d_mbatch_list = random.sample(self.train_d_list, end_idx-start_idx)
              s_mbatch, d_mbatch, s_mbatch_len, d_mbatch_len, snr_mbatch, label_mbatch, _ = \
                  self.wav_batch(s_mbatch_list, d_mbatch_list)
              x_STMS_mbatch, xi_bar_mbatch, _ = \
                  self.training_example(s_mbatch, d_mbatch, s_mbatch_len,
                  d_mbatch_len, snr_mbatch)
              #seq_mask_mbatch = tf.cast(tf.sequence_mask(n_frames_mbatch), tf.float32)
              start_idx += self.mbatch_size; end_idx += self.mbatch_size
              if end_idx &gt; self.n_examples: end_idx = self.n_examples
  
              yield x_STMS_mbatch, xi_bar_mbatch, label_mbatch
  </code></pre>