title: Dataset.from_generator: TypeError: `generator` must be callable
body: <p>I am currently using a generator to produce my training and validation datasets using <code>tf.data.Dataset.from_generator</code>. I have a class method that takes care of this for me:</p>
  <pre><code>def build_dataset(self, batch_size=16, shuffle=16, validation=None):
      
      train_dataset = tf.data.Dataset.from_generator(import_images(validation=validation), (tf.float32, tf.float32))
      self.train_dataset = train_dataset.shuffle(shuffle).repeat(-1).batch(batch_size).prefetch(1)
      
      if validation is not None:
          val_dataset = tf.data.Dataset.from_generator(import_images(validation=validation), (tf.float32, tf.float32))
          self.val_dataset = val_dataset.repeat(1).batch(batch_size).prefetch(1)
  </code></pre>
  <p>The problem is passing in <code>(validation=validation)</code> to my <code>import_images</code> generator creates the generator object which Tensorflow doesn't want, and it gives me the error:</p>
  <pre><code>TypeError: `generator` must be callable.
  </code></pre>
  <p>Because I have to pass in <code>validation</code> to tell my generator to produce a separate training and validation version, I am required to create two versions of the same generator. It also doesn't allow me to pass in other arguments to control the percentage of training and validation examples - meaning the generator has to be static. Any suggestions?</p>