Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. g_1 = tf.Graph()
  2. with g_1.as_default():
  3. # Operations created in this scope will be added to `g_1`.
  4. c = tf.constant("Node in g_1")
  5.  
  6. # Sessions created in this scope will run operations from `g_1`.
  7. sess_1 = tf.Session()
  8.  
  9. g_2 = tf.Graph()
  10. with g_2.as_default():
  11. # Operations created in this scope will be added to `g_2`.
  12. d = tf.constant("Node in g_2")
  13.  
  14. # Alternatively, you can pass a graph when constructing a <a href="../api_docs/python/tf/Session"><code>tf.Session</code></a>:
  15. # `sess_2` will run operations from `g_2`.
  16. sess_2 = tf.Session(graph=g_2)
  17.  
  18. assert c.graph is g_1
  19. assert sess_1.graph is g_1
  20.  
  21. assert d.graph is g_2
  22. assert sess_2.graph is g_2
  23.  
  24. #要检查当前的默认图,请调用 tf.get_default_graph,它会返回一个 tf.Graph 对象:
  25. # Print all of the operations in the default graph.
  26. g = tf.get_default_graph()
  27. print(g.get_operations())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement