Last active
April 16, 2017 21:43
-
-
Save protoget/8de816a14ec0834180bf5362d866de0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| tf.reset_default_graph() | |
| # variables are shared under the same name, in a distributed runtime across different sessions | |
| g1 = tf.Graph() | |
| with g1.as_default(): | |
| with tf.variable_scope('foo'): | |
| w = tf.get_variable('w', shape=[2, 4], initializer=tf.constant_initializer([0, 1, 2, 3, 4, 5, 6, 7])) | |
| init_op = tf.global_variables_initializer() | |
| with tf.Session("grpc://localhost:9000") as sess: | |
| sess.run(init_op) | |
| print "w.name: ", w.name | |
| print sess.run(w) | |
| # variable already initialized | |
| with tf.Session("grpc://localhost:9000") as sess: | |
| # sess.run(init_op) | |
| print "w.name: ", w.name | |
| print sess.run(w) | |
| # hashtables aren't shared under the same name, but under "shared_name", in a distributed runtime, across different sessions | |
| import tensorflow as tf | |
| tf.reset_default_graph() | |
| g1 = tf.Graph() | |
| with g1.as_default(): | |
| print g1 | |
| with tf.name_scope('myscope'): | |
| keys = [1] | |
| values = ["foo"] | |
| t1 = tf.contrib.lookup.HashTable( | |
| tf.contrib.lookup.KeyValueTensorInitializer(keys, values, key_dtype=tf.int64), | |
| "no luck", | |
| name="my_table") | |
| init_op = t1.init | |
| ts = tf.constant([1], dtype=tf.int64) | |
| lookup_op = t1.lookup(ts) | |
| with tf.Session("grpc://localhost:9000") as sess: | |
| sess.run(init_op) | |
| print "t1.name: ", t1.name | |
| print sess.run(lookup_op) | |
| # complain table not initialized | |
| with tf.Session("grpc://localhost:9000") as sess: | |
| # sess.run(init_op) | |
| print "t1.name: ", t1.name | |
| print sess.run(lookup_op) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment