zoukankan      html  css  js  c++  java
  • tf.reset_default_graph()

    tf.reset_default_graph函数用于清除默认图形堆栈并重置全局默认图形。 

    注意:默认图形是当前线程的一个属性。该tf.reset_default_graph函数只适用于当前线程。当一个tf.Session或者tf.InteractiveSession激活时调用这个函数会导致未定义的行为。调用此函数后使用任何以前创建的tf.Operation或tf.Tensor对象将导致未定义的行为。

    with tf.variable_scope('Space_a'):
        a = tf.constant([1,2,3])
    with tf.variable_scope('Space_b'):
        b = tf.constant([7,8,9])
    with tf.variable_scope('Space_c'):
        c= a + b
    d = a+b
    with tf.Session() as sess:
        print(a)
        print(b)
        print(c)
        print(d)
        print(sess.run(c))
        print(sess.run(d))

    Tensor("Space_a/Const:0", shape=(3,), dtype=int32)
    Tensor("Space_b/Const:0", shape=(3,), dtype=int32)
    Tensor("Space_c/add:0", shape=(3,), dtype=int32)
    Tensor("add:0", shape=(3,), dtype=int32)
    [ 8 10 12]
    [ 8 10 12]

    如何清除每次运行时,tensorflow中不断增加的节点并重置整个defualt graph?

    tf.reset_default_graph()#清空dedault graph以及nodes
    with tf.variable_scope('Space_a'):
        a = tf.constant([1,2,3])
    with tf.variable_scope('Space_b'):
        b = tf.constant([7,8,9])
    with tf.variable_scope('Space_c'):
        c= a + b
    d = a+b
    with tf.Session() as sess:
        print(a)
        print(b)
        print(c)
        print(d)
        print(sess.run(c))
        print(sess.run(d))

    Tensor("Space_a/Const:0", shape=(3,), dtype=int32)
    Tensor("Space_b/Const:0", shape=(3,), dtype=int32)
    Tensor("Space_c/add:0", shape=(3,), dtype=int32)
    Tensor("add:0", shape=(3,), dtype=int32)
    [ 8 10 12]
    [ 8 10 12]

  • 相关阅读:
    HDU 4024 Dwarven Sniper’s hunting(数学公式 或者是二分)
    二分图最大匹配总结
    HDU 4022 Bombing (STL应用)
    HDU 1847 Good Luck in CET4 Everybody!(组合博弈)
    HDU 1556 Color the ball(树状数组)
    HDU 4023 Game(博弈)
    HDU 1406 完数(水题)
    HDU 4021 24 Puzzle
    Oracle 多表查询优化
    【编程之美】字符串移位包含的问题(续)
  • 原文地址:https://www.cnblogs.com/tingtin/p/12572757.html
Copyright © 2011-2022 走看看