Get the App
SLTechnology News&Howtos  ›  Development  › 

How to save and recover variables with Saver in TensorFLow

Shulou Source: shulou.com Published: 2022-06-03 19:40:23 10月03日 Update

This article mainly explains "how to save and restore variables in TensorFLow with Saver". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "TensorFLow how to save and restore variables with Saver"!

Create the file tensor_save.py, save the tensor of the variable v1Magee v2 to checkpoint files, and set the name to v3Percience v4, respectively.

Import tensorflow as tf# Create some variables.v1 = tf.Variable (3, name= "v1") v2 = tf.Variable (4, name= "v2") # Create modely=tf.add (v1 Magneto v2) # Add an op to initialize the variables.init_op = tf.initialize_all_variables () # Add ops to save and restore all the variables.saver = tf.train.Saver ({'v3 blemade v1) v4 parallel V2}) # Later, launch the model, initialize the variables, do some work Save the# variables to disk.with tf.Session () as sess: sess.run (init_op) print ("v1 =", v1.eval ()) print ("v2 =", v2.eval ()) # Save the variables to disk. Save_path = saver.save (sess, "f:/tmp/model.ckpt") print ("Model saved in file:", save_path)

Set up the file tensor_restror.py, and restore the tensor named v3menv4 in checkpoint files to the variable v3menv4 respectively.

Import tensorflow as tf# Create some variables.v3 = tf.Variable (0, name= "v3") v4 = tf.Variable (0, name= "v4") # Create modely=tf.mul (v3 Maher v4) # Add ops to save and restore all the variables.saver = tf.train.Saver () # Later, launch the model, use the saver to restore variables from disk, and# do some work with the model.with tf.Session () as sess: # Restore variables from disk. Saver.restore (sess, f:/tmp/model.ckpt) print ("Model restored.") Print ("v3 =", v3.eval ()) print ("v4 =", v4.eval ()) print ("y =", sess.run (y)) so far, I believe you have a better understanding of "how TensorFLow saves and recovers variables with Saver". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Variable content file learning practical deeper interest name practicality practical easy to operate method more friends website channel middle name don't query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker vpn OPPO Reno Redmi