Professional Documents
Culture Documents
Home
PUBLIC
Stack Overflow
Users
Following are 2 code patterns for the training part of Tensorflow NN.
Jobs
I find it logical to use the model 1. But I am seeing model 2 in multiple
2 places frequently. I feel Model 2 is wrong. Wont model run the graph in
Teams session twice for every iteration for the same data? Is there something I
Q&A for work am missing and people do it for any other reasons?
Model 2
If the below sess.run() execute optimizer node, it will execute all its
dependent node. It will run the underlying convnet and loss function as
well.
sess.run(optimizer, feed_dict)
Next if the below sess.run() execute the loss node, why doesnt it execute
the convnet with its current weights. I am not inferring that it will run the
optimization again. Even to arrive at the current loss, wouldnt tensorflow
execute the convnet and calculate the loss?
2 Answers
Session.Run will only run calculate the graph element(s) given to in the first
argument.
1 So in Model 2, sess.run(optimizer, feed_dict) just applies the weight
updates for the model, and loss, accuracy = sess.run([loss,
accuracy],feed_dict) just calculates the loss and accuracy on the model
after weights have been updated. The whole computation isn't being run
twice since these operations are independent of each other.
In Model 1, optimizer is the first fetch for sess.run( ). In that case, are we good
with model 1 as well? – solver149 Oct 30 '18 at 6:39
In model 2, the first line of code runs the optimizer on the model, and the
second line calculates the loss and accuracy. It is not running the graph
0 twice.
Model 1 and Model 2 are essentially the same, but points go to model 1 for
brevity.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.