tensorflow: Weird Bug in Tf.keras.Model.Predict(x=tf.Dataset iterator)
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 16.04
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow installed from (source or binary): pip
- TensorFlow version (use command below): 1.9.0 and 1.12.0 (I am using 1.9.0 but the bug is present in 1.12.0 also)
- Python version: 3.6
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:M60 16 GB (two 8GB GPUs)
Describe the current behavior when using tf.data.Dataset.Iterator in tf.keras.Model.predict(x=tf.data.Dataset.Iterator, steps). I am getting a weird value error:
Please provide data as a list or tuple of 2 elements - input and target pair. Received Tensor(“IteratorGetNext:0”, dtype=int64)
The above error is misleading. why does it need (X,Y) for prediction?
My Testing tf.Dataset iterator obviously does not give a (X,Y) tuple. It gives only X in batches. When I give a numpy array of X as input it works as intended. If I use the dataset iterator with eager_execution enabled: I get this error (my batch size is 2):
Please provide data as a list or tuple of 2 elements - input and target pair. Received tf.Tensor( [[ 68 5 521 … 0 0 0] [ 6705 1235757 2411 … 2804 147 13]], shape=(2, 5000), dtype=int64). We do not use the
target
value here.
Which makes it clear that when eager execution is enabled, Y is not used.
Moreover, why does tf.Dataset iterator need to output a tuple of (X,Y) ? when using tf.keras.Model.predict() ? Is this the expected behaviour?
NOTE: My model is a single input model not a multi input model
EDIT: I worked around the error by providing (X,Y), But the keras progress bar doesn’t seem to work with it.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (5 by maintainers)
@wt-huang I am able to use model.fit() there isn’t any issue there. But the problem is model.predict() requires (X,Y) When I am passing a tf.dataset.iterator But if I pass a numpy it takes only X and works as intended.
i guess i am encountering this error in
tensorflow==1.14.0
, themodel.fit
is finished successfully with tf.data.Dataset input, but themodel.predict
keep giving error:when i construct the dataset with X only, looks it is expecting Y also?
@mrry and @jvishnuvardhan. Thanks! This appears to be fixed in
tf-nightly-1.13.0-dev20190213
The following code snippet threw the error I mentioned when running with <=1.12.0 (stable version)
This runs as intended in nightly version for both normal and eager mode.
One more thing which I really liked was, It doesn’t look like I need to create a
one_shot_iterator
orinitializable_iterator
. I can directly pass thedataset object
tomodel.predict
which feels more natural 👍 . Before, while usingtf.data
with Embedding layers, I had to write a few boilerplate code to initialize lookup tables:My question is do I need to run this boilerplate code in upcoming versions of tensorflow? It will be really great if it is handled internally.