Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tf.data.Dataset.from_generator() empties after use even with repeat() #29123

Closed
mr-ubik opened this issue May 29, 2019 · 2 comments
Closed

tf.data.Dataset.from_generator() empties after use even with repeat() #29123

mr-ubik opened this issue May 29, 2019 · 2 comments

Comments

@mr-ubik
Copy link

mr-ubik commented May 29, 2019

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Arch Linux
  • TensorFlow installed from (source or binary): PyPI binary
  • TensorFlow version (use command below): 2.0.0-dev20190526
  • Python version: 3.7

Describe the current behavior

A tf.data.Dataset created using from_generator() is consumed and not recreated/repeated even when explicitly invoking the repeat() method.

Describe the expected behavior

If repeat() is being invoked, repeat the dataset.

Code to reproduce the issue

#25254 (comment)

Other info / logs

The issue is present both when manually iterating over it in a custom training scenario and when using tf.keras.Model.fit().

@mr-ubik
Copy link
Author

mr-ubik commented May 29, 2019

Actually, it was my fault 🤦‍♂️ I had a generator emptying and not being recreated way way upstream in my pipeline. Sorry ❤️

@mr-ubik mr-ubik closed this as completed May 29, 2019
@zhenghh04
Copy link

zhenghh04 commented May 20, 2021

I encountered the same issue.
I had a python generator: gen
tf.data.Dataset.from_generator(lambda: gen, ....)
It does not support repeat. But if I define a lambda generator outside of tf.data.from_generator(gen_lambda, ...) as follows

gen_lambda = lambda: gen
tf.data.Dataset.from_generator(gen_lambda,  ....) solved the issue. 

It supports repeat method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants