tf.Graph().as_default

as_default() method of tensorflow.python.framework.ops.Graph instance
    Returns a context manager that makes this `Graph` the default graph.
    
    This method should be used if you want to create multiple graphs
    in the same process. For convenience, a global default graph is
    provided, and all ops will be added to this graph if you do not
    create a new graph explicitly. Use this method with the `with` keyword
    to specify that ops created within the scope of a block should be
    added to this graph.
    
    The default graph is a property of the current thread. If you
    create a new thread, and wish to use the default graph in that
    thread, you must explicitly add a `with g.as_default():` in that
    thread's function.
    
    The following code examples are equivalent:
    
    ```python
    # 1. Using Graph.as_default():
    g = tf.Graph()
    with g.as_default():
      c = tf.constant(5.0)
      assert c.graph is g
    
    # 2. Constructing and making default:
    with tf.Graph().as_default() as g:
      c = tf.constant(5.0)
      assert c.graph is g
    ```
    
    Returns:
      A context manager for using this graph as the default graph.

上一篇:《Linux/UNIX OpenLDAP实战指南》——2.10 本章总结


下一篇:《OpenStack云计算实战手册(第2版)》一1.2 使用VirtualBox和Vagrant创建一个沙盒环境