Follow me to learn algorithm-TensorFlow model saving and reading Tf.train.Saver ()

Source: Internet
Author: User

Save = Tf.train.Saver ()

Through save. Save () to implement data loading

Export of data via Save.restore ()

The first step: Data loading

ImportTensorFlow as TF#Creating VariablesV1 = tf. Variable (Tf.random_normal ([1, 2], name='v1')) V2= TF. Variable (Tf.random_normal ([2, 3], name='v2'))#Initialize VariablesInit_op =Tf.global_variables_initializer ()#Building a training model for savingSaver =Tf.train.Saver () with TF. Session () as Sess:sess.run (INIT_OP)Print('V1:', Sess.run (v1))Print('V2:', Sess.run (v2))#Saver.save (save content, save path)Saver_path = Saver.save (Sess,'save/model.ckpt')    Print('Model saved in file:', Saver_path)

Step two: Export of data

ImportTensorFlow as TF
# V1,V2 settings, mainly to see the output of V1 is which v1v1
= TF. Variable (Tf.random_normal ([1, 2]), name='v1') V2= TF. Variable (Tf.random_normal ([2, 3]), name='v2')#Building a Save modelSaver =Tf.train.Saver () with TF. Session () as Sess:#Reload the model (re-give name, Loaded path)Saver.restore (Sess,'save/model.ckpt') Print('V1:', Sess.run (v1))Print('V2:', Sess.run (v2))Print('Model restored')

Follow me to learn algorithm-TensorFlow model saving and reading Tf.train.Saver ()

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.