如何保存经过训练的FCN模型并在经过训练的FCN模型上测试新图像? [英] How to save trained FCN model and test new image on trained FCN model?

查看:399
本文介绍了如何保存经过训练的FCN模型并在经过训练的FCN模型上测试新图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码来训练FCN,我已成功运行了此代码.但是,我想在这种训练有素的模型上测试新图像,有人可以帮助我吗?

I am using this code to train FCN, I have succssfully run this code. However, I want to test new images on this trained model, can anyone help me?

#Training

from keras import optimizers

sgd = optimizers.SGD(lr=1E-2, decay=5**(-4), momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=sgd,
metrics=['accuracy'])

hist1 = model.fit(X_train,y_train,
validation_data=(X_test,y_test),
batch_size=2,epochs=20,verbose=1)

for key in ['loss', 'acc', 'val_loss', 'val_acc']:
plt.plot(hist1.history[key],label=key)
plt.legend()
plt.show()


y_pred = model.predict(X_test)
y_predi = np.argmax(y_pred, axis=3)
y_testi = np.argmax(y_test, axis=3)
print(y_testi.shape,y_predi.shape)

推荐答案

如keras常见问题解答(

As stated in the keras FAQs (https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model):

要将模型保存到磁盘,您可以执行以下操作:

To save your model to your disk you can do:

model.save("my_model_file.h5")

并在以后再次加载它或在另一个文件中加载它以供使用:

And to load it again later or in another file for using it:

from keras.models import load_model

model = load_model("my_model_file.h5")
y_pred = model.predict(X_test)

这篇关于如何保存经过训练的FCN模型并在经过训练的FCN模型上测试新图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆