cnn-text-classification-tf icon indicating copy to clipboard operation
cnn-text-classification-tf copied to clipboard

Add precision and recall summaries

Open ferasodh opened this issue 7 years ago • 4 comments

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,

ferasodh avatar Mar 01 '17 11:03 ferasodh

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

cahya-wirawan avatar Mar 02 '17 11:03 cahya-wirawan

I did that also but this is not useful if you want to use TensorBoard

ferasodh avatar Mar 02 '17 12:03 ferasodh

You should initialize the local variables. Run

sess.run(tf.local_variables_initializer())

priyathamkat avatar Apr 06 '17 03:04 priyathamkat

@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?

naveenjafer avatar Aug 23 '18 12:08 naveenjafer