tensorflow keras save model code example

Example 1: load saved model tensorflow

new_model = tf.keras.models.load_model('my_model.h5')

Example 2: serialize keras model

# Save the modelmodel.save('path_to_my_model.h5')# Recreate the exact same model purely from the filenew_model = keras.models.load_model('path_to_my_model.h5')

Example 3: use model from checkpoint tensorflow

with tf.Session() as sess:
  new_saver = tf.train.import_meta_graph('my_test_model-1000.meta')
  new_saver.restore(sess, tf.train.latest_checkpoint('./'))

Example 4: use model from checkpoint tensorflow

with tf.Session() as sess:    
    saver = tf.train.import_meta_graph('my-model-1000.meta')
    saver.restore(sess,tf.train.latest_checkpoint('./'))
    print(sess.run('w1:0'))
##Model has been restored. Above statement will print the saved value of w1.