AttributeError: 'ShuffleDataset' object has no attribute 'output_shapes' - when following TF tutorial
Asked Answered
C

2

6

I have been working through the TensorFlow tutorials on their website. In the Text Classification with RNN exercise, I encounter this error. I have attempted to a few changes, and have also copy-&-pasted the code to receive the same error. Any suggestions? Thank you

I have tried shuffling the dataset AFTER assigning the padded_batch. I can see from the documentation, there is no attribute (output_shapes) for Shuffle. I cannot figure out an alternative approach.

BUFFER_SIZE = 10000
BATCH_SIZE = 64

train_dataset = train_dataset.shuffle(BUFFER_SIZE)
train_dataset = train_dataset.padded_batch(BATCH_SIZE, train_dataset.output_shapes)

test_dataset = test_dataset.padded_batch(BATCH_SIZE, test_dataset.output_shapes)

to receive this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-8a10fa01af19> in <module>()
      3 
      4 train_dataset = train_dataset.shuffle(BUFFER_SIZE)
----> 5 train_dataset = train_dataset.padded_batch(BATCH_SIZE, train_dataset.output_shapes)
      6 
      7 test_dataset = test_dataset.padded_batch(BATCH_SIZE, test_dataset.output_shapes)

AttributeError: 'ShuffleDataset' object has no attribute 'output_shapes'
Charlettecharley answered 26/4, 2019 at 6:45 Comment(1)
If you're on tf2.0 you can have a look at the link below (not solved yet). Keep if mind that tf 2.0 is still on alpha and is thus not completely bug free github.com/tensorflow/tensorflow/issues/28083Jumpy
M
10

Try replacing

train_dataset = train_dataset.padded_batch(BATCH_SIZE, train_dataset.output_shapes)

with

train_dataset = train_dataset.padded_batch(BATCH_SIZE, tf.compat.v1.data.get_output_shapes(train_dataset))

it is not part of the question but you can also write your train_dataset all in one go, for example:

train_dataset = (
    train_dataset
    .shuffle(BUFFER_SIZE)
    .padded_batch(BATCH_SIZE, tf.compat.v1.data.get_output_shapes(train_dataset)))

figured I would throw that in there just to give another way of writing it ;)

Also, as far as train_dataset.output_shapes goes, it has been depreciated in the latest version of TensorFlow https://www.tensorflow.org/api_docs/python/tf/data/Dataset#element_spec so if you have TF2 you can use compat.v1 or ds.element_spec

Moneychanger answered 17/12, 2019 at 2:8 Comment(0)
N
0

Replace it by

BUFFER_SIZE = 10000
BATCH_SIZE = 64

train_dataset = train_dataset.shuffle(BUFFER_SIZE)
train_dataset = train_dataset.padded_batch(BATCH_SIZE, tf.compat.v1.data.get_output_shapes(train_dataset))
test_dataset = test_dataset.padded_batch(BATCH_SIZE, tf.compat.v1.data.get_output_shapes(test_dataset))
Narvaez answered 23/1, 2021 at 6:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.