I tried to add some additional measurements to my training code for a CNN by utilising the functions from the tf.metrics
submodule, such as tf.metrics.accuracy(y_labels, y_predicted)
and equivalents for precision or recall. This is done in contrast to most of their tutorials where they suggest the convoluted:
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
Whereas my implementation replaces this line with:
accuracy = tf.metrics.accuracy(y_labels, y_predicted)
Now, even though I do the sess.run(tf.initialize_all_variables())
within my with tf.Session() as sess:
block, I still get the following error when trying to use tf.metrics.accuracy
function:
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value performance/accuracy/count
[[Node: performance/accuracy/count/read = Identity[T=DT_FLOAT, _class=["loc:@performance/accuracy/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](performance/accuracy/count)]]
Most notably, replacing the accuracy = tf.metrics.accuracy(y_labels, y_predicted)
line with accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
fixes the problem, however, I would like to implement other metrics such as precision, recall, etc. without doing it by hand.