September 2017
Intermediate to advanced
622 pages
15h 13m
English
Executing variables and operators by their names is very useful in many scenarios. For example, we may develop a model in a separate module; and thus the variables are not available in a different Python scope according to Python scoping rules. However, if we have a graph, we can execute the nodes of the graph using their names in the graph.
This can be done easily by changing the sess.run method from the previous code example, using the variable name of the cost in the graph rather than the Python variable cost by changing sess.run([cost, train_op], ...) to sess.run(['cost:0', 'train_op'], ...).
>>> n_epochs = 500 >>> training_costs = [] >>> with tf.Session(graph=g) as sess: ... ## first, ...