January 2018
Intermediate to advanced
474 pages
10h 23m
English
Let us enable the logging of variable placement by defining a config object, set the log_device_placement property to true, and then pass this config object to the session as follows:
tf.reset_default_graph()# Define model parametersw = tf.Variable([.3], tf.float32)b = tf.Variable([-.3], tf.float32)# Define model input and outputx = tf.placeholder(tf.float32)y = w * x + bconfig = tf.ConfigProto()config.log_device_placement=Truewith tf.Session(config=config) as tfs: # initialize and print the variable y tfs.run(global_variables_initializer()) print('output',tfs.run(y,{x:[1,2,3,4]}))
We get the following output in Jupyter Notebook console:
b: (VariableV2): /job:localhost/replica:0/task:0/device:GPU:0 ...
Read now
Unlock full access