在Keras中准备imdb数据时报错AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'
from keras.datasets import imdb
from keras.preprocessing import sequence
max_features = 10000
maxlen = 500
batch_size = 32
print('Lodaing data...')
(input_train, y_train), (input_test, y_test) = imdb.load_data(num_words=max_features)
print(len(input_train), 'train sequences')
print(len(input_test), 'test sequences')
print('Pad sequences (sample x time)')
input_train = sequence.pad_sequences(input_train, maxlen=maxlen)
input_test = sequence.pad_sequences(input_test, maxlen=maxlen)
print('input_train shape:', input_train.shape)
print('input_test shape:', input_test.shape)
运行结果如下:
Lodaing data...
25000 train sequences
25000 test sequences
Pad sequences (sample x time)
Traceback (most recent call last):
File "D:\Projects\LSTM\LSTM1\dataset.py", line 15, in <module>
input_train = sequence.pad_sequences(input_train, maxlen=maxlen)
AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'
重新安装过keras还是有这个问题,我的Keras版本是2.9.0,tensorflow的版本是2.9.1