TensorFlow Learning (11) Writing Python code to a file

Source: Internet
Author: User

#Save to fileImportTensorFlow as TFImportNumPy as NP## (1) Save to file stores related variables in Files#Remember to define the same dtype and shape when restoreW = tf. Variable ([[1,2,3],[3,4,5]],dtype=tf.float32,name='Weights') b= TF. Variable ([[1,2,3]],dtype=tf.float32,name='biases') Init=tf.initialize_all_variables () 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)## (2) Restore variables remove the relevant variable from the file#redefine the same shape and same type for you variablesW = tf. Variable (Np.arange (6). Reshape ((2,3)), dtype=tf.float32,name="Weights")#reshape ((2,3): 2 rows 3 Columnsb = tf. Variable (Np.arange (3). Reshape ((1,3)), dtype=tf.float32,name="biases")#Not need init stepSaver =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))

TensorFlow Learning (11) Writing Python code to a file

Related Article

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.