我遇到了问题。 我正在尝试做的是建立一个深度学习神经网络。我创建了模型并对其进行了学习,但是训练完模型后我想做的是:我想加载最后一个模型(训练有素的模型)。
所以我尝试了这个:
# unique file name that will include the epoch and the validation acc for that epoch
filepath = "RNN_Final-{epoch:02d}-{val_acc:.3f}"
# saves only the best ones
checkpoint = ModelCheckpoint("/var/www/test.nl/models/{}.model".format(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max'))
last_model = "/var/www/test.nl/models/{}.model".format(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
# Train model
history = model.fit(
train_x, train_y,
batch_size=BATCH_SIZE,
epochs=EPOCHS,
validation_data=(validation_x, validation_y),
callbacks=[tensorboard, checkpoint])
new_model = tf.keras.models.load_model(last_model)
predictions = new.model.predict([train_x])
print(np.argmax(predictions[0]))
但这会尝试打开此文件:
Unable to open file (unable to open file: name = '/var/www/test.nl/models/RNN_Final-{epoch:02d}-{val_acc:.3f}.model', errno = 2, error message = 'No such file or directory'
我要打开的模型称为:
RNN_Final-30-0.555.model
那我在做什么错了?