sample_freeze_restore.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:sktacc 作者: jclee81 项目源码 文件源码
def run():
    log.info('Run freeze restore')

    y = tf.Variable([float(88.8), float(5)], name='y1')
    # print(y.op.node_def)
    init_op = tf.global_variables_initializer()

    with tf.Session() as sess:
        sess.run(init_op)
        # sess.run(y)
        g = sess.graph
        g_def = g.as_graph_def()

        # print node names
        # print([n.name for n in g_def.node])

        # constants
        constants = graph_util.convert_variables_to_constants(
            sess, g_def, ['y1'])

        # serialize
        s = constants.SerializeToString()
        # print(len(g_def.node))
        print_nodes(g.as_graph_def(), 'before restore:')
        _ = restore_graph(s)
        print_nodes(g.as_graph_def(), 'after restore:')
        t = g.get_tensor_by_name('restore/y1:0')

        sess.run(y.assign(y + t))
        print(sess.run(y))
        # print(len(g_def.node))
        # print(sess.run(y.assign([float(99.9)])))
        # print(n)
        # print(sess.run(y.assign(n)))
        # g2 = tf.Graph()
        # g2_def = g2.as_graph_def()
        # print([n.name for n in g2_def.node])

# run()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号