TensorFlow 2.0教程问题

时间:2019-04-16 05:38:42

标签: python tensorflow tensorflow2.0

我正在关注https://www.tensorflow.org/alpha/tutorials/sequences/text_classification_rnn上的官方教程,但遇到了问题。以下行会导致错误:

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

回溯(最近通话最近):     在第30行的文件“ main.py”中       train_dataset = train_dataset.padded_batch(BATCH_SIZE,train_dataset.output_shapes)   AttributeError:“ 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)

1 个答案:

答案 0 :(得分:0)

请更换

resizeMode : cover

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)