How to load trained keras model once and predict on individual input multiple times?

874 views
Skip to first unread message

search...@gmail.com

unread,
Mar 2, 2017, 9:23:12 AM3/2/17
to Keras-users
Hi,

How to load trained keras model once and predict on individual input across method call?
If for each input to method, I load keras model and weights, it becomes very slow as it takes time to load model.

Please suggest.


Thanks,
Mahesh

jpeg729

unread,
Mar 3, 2017, 12:14:58 PM3/3/17
to Keras-users, search...@gmail.com
Just run 

prediction = model.predict(input)

for each input. No need to reload the model each time.

search...@gmail.com

unread,
Mar 6, 2017, 11:47:22 PM3/6/17
to Keras-users, search...@gmail.com
Hi,

Thanks for reply.

My problem is I am doing this in Python method. for every new input I am calling this method where I have to load the model.
I might be needing some global variables to save keras model and reuse that.
I am new to python.

Please suggest.

Thanks,
Mahesh

tempd...@gmail.com

unread,
Sep 28, 2018, 12:53:53 AM9/28/18
to Keras-users
Hi,

You can write a function with parameters or define a class. The class includes a keras model as its member. So an instance of the class will keep the model and no need to reload  it every time.



在 2017年3月7日星期二 UTC+8下午12:47:22,search...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages