瀏覽代碼

the first step

youchen 7 年之前
父節點
當前提交
4270ed650e
共有 1 個文件被更改,包括 32 次插入0 次删除
  1. 32 0
      graph_test.py

+ 32 - 0
graph_test.py

@@ -0,0 +1,32 @@
+import tensorflow as tf
+
+g1 = tf.Graph()
+with g1.as_default():
+    v = tf.get_variable(
+        "v", initializer=tf.zeros_initializer()(shape=[1])
+    )
+
+g2 = tf.Graph()
+with g2.as_default():
+    v = tf.get_variable(
+        "v", initializer=tf.ones_initializer()(shape=[1])
+    )
+
+with tf.Session(graph=g1) as sess:
+    tf.global_variables_initializer().run()
+    with tf.variable_scope("", reuse=True):
+        print(sess.run(tf.get_variable("v")))
+
+with tf.Session(graph=g2) as sess:
+    tf.global_variables_initializer().run()
+    with tf.variable_scope("", reuse=True):
+        print(sess.run(tf.get_variable("v")))
+
+# gpu acceleration
+a = tf.constant([1.0, 3.0], name="a")
+b = tf.constant([3.0, 6.0], name="b")
+g = tf.Graph()
+with g.device('/gpu:0'):
+    result = a+b
+    sess = tf.Session()
+    print (sess.run(result))