cnn-text-classification-tf
cnn-text-classification-tf copied to clipboard
Add precision and recall summaries
How can the code be modified to log precision and recall? I tried to add precision in text_cnn class as follows:
self.precision =tf.contrib.metrics.streaming_precision(logits1, self.input_y, name="precision")
and I added the summary to train file
precision_summary = tf.summary.scalar("precision", cnn.precision)
but this triggers the following error
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value accuracy/precision/true_positives/count [[Node: accuracy/precision/true_positives/count/read = Identity[T=DT_FLOAT, _class=["loc:@accuracy/precision/true_positives/count"], _device="/job:localhost/replica:0/task:0/cpu:0"](accuracy/precision/true_positives/count)]]
Any ideas how to solve this? or any other way to add precision and recall?
Thanks,
I print out the precision, recall and f1-score only at the end of the test evaluation (using metrics from sklearns): https://github.com/cahya-wirawan/cnn-text-classification-tf/blob/master/eval.py
I did that also but this is not useful if you want to use TensorBoard
You should initialize the local variables. Run
sess.run(tf.local_variables_initializer())
@ferasodh Hi, I was running into similar errors too. The session is initialized as follows for the Dev process.
step, summaries, loss, accuracy, precision = sess.run( [global_step, dev_summary_op, cnn.loss, cnn.accuracy, cnn.precision], feed_dict)
and the new named scope for precision is
with tf.name_scope("precision"): self.precision = tf.metrics.precision(tf.argmax(self.input_y, 1), self.predictions)
can someone help with this?