"Tensorflow1.0 Learning note 006" Save-restore Save and read

Source: Internet
Author: User

Saver Instance Code:

# # Save to File
# Remember to define the same dtype and shape when restore
W = tf. Variable ([[[1,2,3],[3,4,5]], dtype=tf.float32, name= ' weights ')
B = tf. Variable ([[[Dtype=tf.float32]],, name= ' biases ')

init= tf.global_variables_initialize ()

saver = Tf.train.Saver () with

TF. Session () as Sess:
   sess.run (init)
   Save_path = Saver.save (Sess, "my_net/save_net.ckpt")
   print ("Save to Path: ", Save_path)

Restore Instance code:

# Restore Variables
# redefine the same shape and same type for your variables
W = tf. Variable (Np.arange (6). Reshape ((2, 3)), Dtype=tf.float32, name= "weights")
B = tf. Variable (Np.arange (3). Reshape ((1, 3)), Dtype=tf.float32, name= "biases")

# not need init step

saver = Tf.train.Saver () with
TF. Session () as Sess:
    saver.restore (Sess, "my_net/save_net.ckpt")
    print ("Weights:", Sess.run (W))
    Print ("Biases:", Sess.run (b))

After a saver.save (), you can see the new four files in the folder:

The checkpoint file holds a list of the many model files that are recorded Model.ckpt.meta saved the structure of the TensorFlow calculation diagram, Model.ckpt Save the value of each variable, where the file name is written differently depending on the settings of the different parameters, but the file path name when the restore was loaded is in the checkpoint file The "Model_checkpoint_path" value is determined. The simple understanding is that the weights and other parameters are saved to the. chkp.data file, in the form of a dictionary; diagrams and metadata are saved to the. chkp.meta file, which can be tf.train.import_meta_graph loaded into the current default diagram.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.