[英]AttributeError: 'ShuffleDataset' object has no attribute 'output_shapes' - when following TF tutorial
I have been working through the TensorFlow tutorials on their website.我一直在学习他们网站上的 TensorFlow 教程。 In the Text Classification with RNN exercise, I encounter this error.
在使用 RNN 进行文本分类练习中,我遇到了这个错误。 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.我已经尝试在分配 padded_batch 后改组数据集。 I can see from the documentation, there is no attribute (output_shapes) for Shuffle.
我可以从文档中看到,Shuffle 没有属性 (output_shapes)。 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'
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 = (
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此外,就 train_dataset.output_shapes 而言,它在最新版本的 TensorFlow 中已贬值https://www.tensorflow.org/api_docs/python/tf/data/Dataset#element_spec所以如果你有 TF2 你可以使用 compat .v1 或 ds.element_spec
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.