栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从文件打开张量流图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从文件打开张量流图

我以这种方式解决了这个问题:首先,我在图形“输出”中命名所需的计算,然后将此模型保存在下面的代码中…

import tensorflow as tfx = tf.placeholder(dtype=tf.float64, shape=[], name="input")a = tf.Variable(111, name="var1", dtype=tf.float64)b = tf.Variable(-666, name="var2", dtype=tf.float64)y = tf.add(x, a, name="output")saver = tf.train.Saver()with tf.Session() as sess:    tf.initialize_all_variables().run()    print(sess.run(y, feed_dict={x: 555}))    save_path = saver.save(sess, "model.ckpt", meta_graph_suffix='meta', write_meta_graph=True)    print("Model saved in file: %s" % save_path)

其次,我需要在图形中运行某些操作,我将其称为“输出”。因此,我只是用另一个代码还原模型,并通过使用名称为“ input”和“
output”的必要图形部分来运行还原的计算:

import tensorflow as tf# Restore graph to another graph (and make it default graph) and variablesgraph = tf.Graph()with graph.as_default():    saver = tf.train.import_meta_graph("model.ckpt.meta")    y = graph.get_tensor_by_name("output:0")    x = graph.get_tensor_by_name("input:0")    with tf.Session() as sess:        saver.restore(sess, "model.ckpt")        print(sess.run(y, feed_dict={x: 888}))        # Variable out:        for var in tf.all_variables(): print("%s %.2f" % (var.name, var.eval()))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646545.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号