如何保存经过训练的FCN模型并在经过训练的FCN模型上测试新图像?

时间:2019-08-19 06:55:29

标签: python keras

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

#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)

1 个答案:

答案 0 :(得分:0)

如喀拉拉邦常见问题(https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model)中所述:

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

<input type="number" placeholder="Amount" name="repeat[0][amount]" class="form-control">

public function add()
{
    $locations = $_POST['repeat'];
    foreach ($locations as $key => $subValue) {

    echo $subValue['amount'];
}

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

model.save("my_model_file.h5")