You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

train_saver.py 761 B

1234567891011121314151617181920212223242526
  1. 
  2. import tensorflow as tf
  3. # Create some variables.
  4. v1 = tf.get_variable("v1", shape=[3], initializer = tf.zeros_initializer)
  5. v2 = tf.get_variable("v2", shape=[5], initializer = tf.zeros_initializer)
  6. inc_v1 = v1.assign(v1+1)
  7. dec_v2 = v2.assign(v2-1)
  8. # Add an op to initialize the variables.
  9. init_op = tf.global_variables_initializer()
  10. # Add ops to save and restore all the variables.
  11. saver = tf.train.Saver()
  12. # Later, launch the model, initialize the variables, do some work, and save the
  13. # variables to disk.
  14. with tf.Session() as sess:
  15. sess.run(init_op)
  16. # Do some work with the model.
  17. inc_v1.op.run()
  18. dec_v2.op.run()
  19. # Save the variables to disk.
  20. save_path = saver.save(sess, "/tmp/model.ckpt")
  21. print("Model saved in path: %s" % save_path)

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。