keras 加载model.save加载模型(“model_name.h5”)时保存...>属性错误:“string”对象没有属性“decode”

vltsax25  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(101)

我有一个困难的时间保存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”

k4emjkb1

k4emjkb11#

尝试下面的代码,让我知道如果这工程或没有!

# load model package
from keras.models import load_model

# load model
new_model = load_model("model_test.h5")

相关问题