tensorflow保存模型

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')))

这个程序有点糊弄人!自己现在还没有完全搞明白!(这个博客算是凑篇数的)
今天有点浮躁沉不下心来!越到考试越想放松,啥都不想干!

发布了49 篇原创文章 · 获赞 18 · 访问量 1411

猜你喜欢

转载自blog.csdn.net/qq_44099721/article/details/103789048
今日推荐