Skip to content Skip to sidebar Skip to footer

How To Calculate Loss Without Updating Model In Tensorflow

To my understanding, below code will calculate loss and update parameters in the model at the same time. _, c = sess.run([optimizer, loss], feed_dict={x:x, y:y}) so how to calcula

Solution 1:

To calculate the loss without updating the model, simply run the loss operation, without the optimizer operation.

c = sess.run(loss, feed_dict={x:x, y:y})

Note that when you run sess.run([optimizer, loss], feed_dict={x:x, y:y}) you get the loss value before applying the updates, so running:

_, c1 = sess.run([optimizer, loss], feed_dict={x:x, y:y})
c2 = sess.run(loss, feed_dict={x:x, y:y})

Will still yield different values of c1 and c2, since c2 is the loss value after updating the model.

Post a Comment for "How To Calculate Loss Without Updating Model In Tensorflow"