BorgwardtLab / mgp-tcn

Sepsis Prediction on MIMIC
BSD 3-Clause "New" or "Revised" License
69 stars 25 forks source link

How to save and load a trained model? #10

Closed la122 closed 3 years ago

la122 commented 4 years ago

Hello, thank you for publishing your work!

is it possible to load a checkpoint and use it for predictions after training? I'm trying something like:

sess = tf.Session()
sess.run(tf.global_variables_initializer())
loader = tf.train.import_meta_graph('mock_data_results/model_checkpoints/epoch_29-1342.meta')
loader.restore(sess, tf.train.latest_checkpoint('mock_data_results/model_checkpoints'))
probs = tf.get_default_graph().get_tensor_by_name('while_1/Exit_1:0')
probs.eval(session=sess, feed_dict=feed_dict)

But the results are exactly the same as without restoring the checkpoint.

Best regards

la122 commented 3 years ago

I managed to load a checkpoint after rebuilding the graph with the placeholders and using the following code:

with tf.Session(config=config) as sess:
  saver = tf.train.Saver()
  saver.restore(sess, 'experiments/config/model_checkpoints/epoch_XX')
  ...