Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

python - Get predictions from Keras/Tensorflow once model is trained

I am working on a project involving neural machine translation (translating English to French).

I have worked through some examples online, and have now finished the model. Once a model is trained using Keras, how do I then get a prediction of a translation without training the entire model again, because with the large dataset I am using, each epoch takes some time and of course, I can't train the model every time I want a translation.

So what is the correct way of then generating predictions on new inputs without training the whole model again?

Thanks

enter image description here

enter image description here

question from:https://stackoverflow.com/questions/65923671/get-predictions-from-keras-tensorflow-once-model-is-trained

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to save your model the model and its weights when the fit ends using :

keras.model.save(model_name)

At any time, you can load your trained model using

model = keras.load(model_name)

then perform predictions as

y_pred = model.predict(x_test)

Hope this will be helpful


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...