You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
contrib.data.Dataset - doc issue with Dataset.map / tf.py_func in 1.3.0rc0 #11786
Cannot convert a list containing a tensor of dtype <dtype: 'int32'> to <dtype: 'uint8'> (Tensor is: <tf.Tensor 'PyFunc:1' shape=<unknown> dtype=int32>)
This is due to the breaking change mentioned in release notes. To fix, one now has to introduce an explicit tuple() like so
@mrry You're welcome. While this is certainly a doc issue at this point, I want to raise the concern that assigning tuple and list totally different semantics in Python is very uncommon (even in Tensorflow) and could lead to many suprising moments on user side.
where decoder is a tf.contrib.slim.tfexample_decoder.TFExampleDecoder()
So, if I got the issue right, since decoder.decode() returns a list[label, decoded_image_data] this is implicitly casted to a tensor (and thus the cast fails because label and image_data have different types).
However, if I write a lambda that wraps tuple() around the result of the call to decoder.decode(), this should fix the problem:
dataset = dataset.map( lambda s : tuple(decoder.decode(s, items=['label', 'image'])))
I still get the error, however:
TypeError: Cannot convert a list containing a tensor of dtype <dtype: 'float32'> to <dtype: 'int64'> (Tensor is: <tf.Tensor 'distort_image/Mul:0' shape=(224, 224, 3) dtype=float32>)
Am I getting the solution wrong? Is this really the intended way to use the API? Even when many other TF APIs return lists instead of tuples?
EDIT: I had map() in several places and, of course, the new error was coming from the line below the one I fixed.
@GPhilo We've fixed this issue in the internal branch, and it should appear at HEAD soon. (Follow #12396 to see when the commit lands.) After the fix, the behavior of Dataset.map() will be the same if a function returns a tuple or a list containing the same elements, and the tuple(...) workaround will no longer be necessary.
TypeError: Cannot convert a list containing a tensor of dtype <dtype: 'int32'> to <dtype: 'float32'> (Tensor is: <tf.Tensor 'Preprocessor/stack_1:0' shape=(1, 3) dtype=int32>)
Reacted by tamizh, Adibhatt95, firesnow1234, ekfkdlxm, ObOsCode and LTOM
@tamizharasank This issue has been closed. If you think you've found a bug, please open a new issue with enough details about your program to reproduce the problem. Otherwise, Stack Overflow may be a more useful venue for your question.
Activity
aselle commentedon Jul 26, 2017
@mrry, could you update the documentation to reflect this change?
aselle commentedon Jul 26, 2017
Thanks @cheind for reporting this.
cheind commentedon Jul 27, 2017
@mrry You're welcome. While this is certainly a doc issue at this point, I want to raise the concern that assigning
tupleandlisttotally different semantics in Python is very uncommon (even in Tensorflow) and could lead to many suprising moments on user side.[tf.contrib.data] map expects a nested structure.
Merge changes from github.
GPhilo commentedon Aug 21, 2017
I have a similar error message, but I'm not sure if I got the proposed solution correctly.
The code raising the error:
where
decoderis atf.contrib.slim.tfexample_decoder.TFExampleDecoder()So, if I got the issue right, since
decoder.decode()returns a list[label, decoded_image_data]this is implicitly casted to a tensor (and thus the cast fails becauselabelandimage_datahave different types).However, if I write a lambda that wraps tuple() around the result of the call to
decoder.decode(), this should fix the problem:I still get the error, however:Am I getting the solution wrong? Is this really the intended way to use the API? Even when many other TF APIs return lists instead of tuples?
EDIT: I had map() in several places and, of course, the new error was coming from the line below the one I fixed.
mrry commentedon Aug 21, 2017
@GPhilo We've fixed this issue in the internal branch, and it should appear at HEAD soon. (Follow #12396 to see when the commit lands.) After the fix, the behavior of
Dataset.map()will be the same if a function returns a tuple or a list containing the same elements, and thetuple(...)workaround will no longer be necessary.cheind commentedon Aug 22, 2017
@mrry sounds great!
tamizharasank commentedon Jul 20, 2018
TypeError: Cannot convert a list containing a tensor of dtype <dtype: 'int32'> to <dtype: 'float32'> (Tensor is: <tf.Tensor 'Preprocessor/stack_1:0' shape=(1, 3) dtype=int32>)
mrry commentedon Jul 20, 2018
@tamizharasank This issue has been closed. If you think you've found a bug, please open a new issue with enough details about your program to reproduce the problem. Otherwise, Stack Overflow may be a more useful venue for your question.