简体   繁体   English

AttributeError: 'ShuffleDataset' 对象没有属性 'output_shapes' - 遵循 TF 教程时

[英]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.

相关问题 “AutoTrackable”对象没有属性“output_shapes” - 'AutoTrackable' object has no attribute 'output_shapes' AttributeError: &#39;ShuffleDataset&#39; 对象没有属性 &#39;features&#39; - AttributeError: 'ShuffleDataset' object has no attribute 'features' 获取属性错误 TensorDataset object 没有属性“输出形状”问题 - Getting Attribute Error TensorDataset object has no attribute 'output_shapes' issue AttributeError: 'Sheet' object 没有属性 'Shapes' - AttributeError: 'Sheet' object has no attribute 'Shapes' AttributeError:使用tf-faster-rcnn时,“模块”对象没有属性“直方图” - AttributeError: 'module' object has no attribute 'histogram' when using tf-faster-rcnn Django noob:AttributeError:“模块”对象没有属性“索引”(官方教程) - Django noob: AttributeError: 'module' object has no attribute 'index' (Official tutorial) tensorflow教程代码失败并出现AttributeError:“ Tensor”对象没有属性“ numpy” - tensorflow tutorial code fails with AttributeError: 'Tensor' object has no attribute 'numpy' Openmdao-AttributeError:“抛物线”对象中的“ float”对象没有属性“ size” - Openmdao - AttributeError: 'float' object has no attribute 'size' in Paraboloid Tutorial AttributeError:&#39;int&#39;对象没有属性&#39;output&#39; - AttributeError: 'int' object has no attribute 'output' AttributeError:“ list”对象在TF-IDF中没有属性“ lower” - AttributeError: 'list' object has no attribute 'lower' in TF-IDF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM