Datasets: AttributeError: 'ShuffleDataset' object has no attribute 'output_shapes'

Created on 8 Dec 2019  路  5Comments  路  Source: tensorflow/datasets

Text classification with an RNN with the tutorial:
https://www.tensorflow.org/tutorials/text/text_classification_rnn
Description of the bug.

Environment information

  • Operating System: Windows 8.1
  • Python version: 3.6.4
  • tensorflow-datasets/tfds-nightly version: 1.3.2
  • tensorflow/tensorflow-gpu/tf-nightly/tf-nightly-gpu version: <2.0.0

Reproduction instructions

from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow_datasets as tfds
import tensorflow as tf

dataset, info = tfds.load('imdb_reviews/subwords8k', with_info=True, as_supervised=True)
train_dataset, test_dataset = dataset['train'], dataset['test']

encoder = info.features['text'].encoder

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)

Link to logs
2019-12-08 17:20:18.271202: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "C:/Users/Oskar/Desktop/Twitter/analiza/main1.py", line 51, in
train_dataset = train_dataset.padded_batch(BATCH_SIZE, train_dataset.output_shapes)
AttributeError: 'ShuffleDataset' object has no attribute 'output_shapes'

Expected behavior
Should go run the above code without any error.

bug

Most helpful comment

change "train_dataset.output_shapes" to "tf.compat.v1.data.get_output_shapes(train_dataset)"

All 5 comments

change "train_dataset.output_shapes" to "tf.compat.v1.data.get_output_shapes(train_dataset)"

output_shapes is deprecated in TF2, you can use the compat.v1 or use ds.element_spec: https://www.tensorflow.org/api_docs/python/tf/data/Dataset#element_spec

shapes = tf.nest.map_structure(
    lambda spec: spec.shape,
    ds.element_spec,
)

change "train_dataset.output_shapes" to "tf.compat.v1.data.get_output_shapes(train_dataset)"

worked for me! thanks to zaabek

Thanks it woked for me too.

thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings