TensorFlow 2.0 教程问题



我正在按照 https://www.tensorflow.org/alpha/tutorials/sequences/text_classification_rnn 的官方教程进行操作,遇到了一个问题。以下行导致错误:

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

回溯(最近一次调用(: 文件"main.py",第 30 行,在 train_dataset = train_dataset.ppad_batch(BATCH_SIZE, train_dataset.output_shapes( 属性错误:"ShuffleDataset"对象没有属性"output_shapes

我错过了什么?这是我半完成的代码:

from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow_datasets as tfds
import tensorflow as tf
import matplotlib.pyplot as plt
import tensorflow.keras
def plot_graphs(history, string):
    plt.plot(history.history[string])
    plt.plot(history.history['val_'+string])
    plt.xlabel("Epochs")
    plt.ylabel(string)
    plt.legend([string, 'val_'+string])
    plt.show()
dataset, info = tfds.load('imdb_reviews/subwords8k', with_info=True,
                          as_supervised=True)
train_dataset, test_dataset = dataset['train'], dataset['test']
tokenizer = info.features['text'].encoder
print ('Vocabulary size: {}'.format(tokenizer.vocab_size))
# sample_string = 'TensorFlow is cool.'
# tokenized_string = tokenizer.encode(sample_string)
# print ('Tokenized string is {}'.format(tokenized_string))
# original_string = tokenizer.decode(tokenized_string)
# print ('The original string: {}'.format(original_string))
# assert original_string == sample_string
# for ts in tokenized_string:
#     print ('{} ----> {}'.format(ts, tokenizer.decode([ts])))
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)

请替换

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

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, test_dataset.output_shapes)

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

最新更新