Log:
C:\ Users \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ keras \ engine \ sequential.py:110:
UserWarning:不推荐使用
Sequential.model
。Sequential
是Model
的子类,您可以只使用Sequential
实例直。 warnings.warn('Sequential.model
已过时。'
在jupyter笔记本中执行模型时,其以.ipynb
文件格式工作,但在以.py
文件格式的VS代码执行时停止工作。
代码:
from keras.models import Sequential
from keras.layers import Dense, Activation, Embedding, Flatten, LSTM, Dropout, Conv1D, SpatialDropout1D
from keras.optimizers import Adam
model = Sequential()
model.add(Embedding(max_fatures, embed_dim,input_length = x.shape[1]))
model.add(SpatialDropout1D(0.5))
model.compile(loss = 'categorical_crossentropy', optimizer='adam',metrics = ['acc'])
model.summary()
保存模型:
model.model.save('my_model.h5')
with open('tokenizer.pickle', 'wb') as handle:
pickle.dump(tokenizer, handle, protocol=pickle.HIGHEST_PROTOCOL)
[UserWarning