我有一个困难的时间保存keras模型和加载它。
它继续提高:属性错误:“string”对象没有属性“decode”
当我load_model()
import numpy as np
import pandas as pd
from keras.utils import to_categorical
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers import LSTM, Dense, GRU, Embedding
from keras.callbacks import EarlyStopping, ModelCheckpoint
activation='softmax'
loss ='categorical_crossentropy'
optimizer ='adam'
epochs = 2
# generate model
model = Sequential()
model.add(Embedding(vocab, 100, input_length=n, trainable=True))
model.add(GRU(150, recurrent_dropout=0.1, dropout=0.1))
model.add(Dense(vocab, activation=activation))
print(model.summary())
# compile the model
model.compile(loss=loss, metrics=['acc'], optimizer=optimizer)
# fit the model
model.fit(X_tr, y_tr, epochs=epochs, verbose=2, validation_data=(X_val, y_val))
# saving model
model.save("model_test.h5")
# load model
from keras.models import load_model
# load model
new_model = tf.keras.models.load_model("model_test")
返回:属性错误:“string”对象没有属性“decode”
1条答案
按热度按时间k4emjkb11#
尝试下面的代码,让我知道如果这工程或没有!