import tensorflow as tf
# with tf.device('/gpu:0'):
# V1 = tf.Variable(tf.constant(1.0, shape=[1]), name='V1')
# V2 = tf.Variable(tf.constant(2.0, shape=[1]), name='V2')
# result = V1 + V2
# init_op = tf.global_variables_initializer()
# # 保存模型
# saver = tf.train.Saver()
#
#
# with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess:
# sess.run(init_op)
# #
# saver.save(sess, r'E:\ZC\procedure\tensorflow_gpu\model\model.ckpt')
# print(sess.run(result))
# writer = tf.summary.FileWriter(r'E:\ZC\procedure\tensorflow_gpu\Log', tf.get_default_graph())
# writer.close()
#
# # 只能算原來圖中的數據
# with tf.device('/gpu:0'):
# V1 = tf.Variable(tf.constant(2.0, shape=[1]), name='V1')
# V2 = tf.Variable(tf.constant(2.0, shape=[1]), name='V2')
# result = V1 + V2
# saver = tf.train.Saver()
# with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess:
# saver.restore(sess, r'E:\ZC\procedure\tensorflow_gpu\model\model.ckpt')
# print(sess.run(result))
# 不需要重複定義原始圖中的運算
# 直接加載持久化的圖
saver = tf.train.import_meta_graph(r'E:\ZC\procedure\tensorflow_gpu\model\model.ckpt.meta')
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess:
saver.restore(sess, r'E:\ZC\procedure\tensorflow_gpu\model\model.ckpt')
# 通過張量名字獲取張量
print(sess.run(tf.get_default_graph().get_tensor_by_name('add:0')))
這個程序有點糊弄人!自己現在還沒有完全搞明白!(這個博客算是湊篇數的)
今天有點浮躁沉不下心來!越到考試越想放鬆,啥都不想幹!