TensorFlow: is there a metric for calculating and updating top accuracy k?

The current tf.contrib.metrics.streaming_accuracyis able to calculate only the upper accuracy, and not the upper k. As a workaround, this is what I used:

tf.reduce_mean(tf.cast(tf.nn.in_top_k(predictions=predictions, targets=labels, k=5), tf.float32))

However, this does not allow me to calculate the accuracy of the streaming transmission averaged over each batch, which would be useful for obtaining a stable accuracy of the estimate. I am currently manually calculating this 5 streaming accuracy using its numpy output, but this means that I cannot visualize this metric on the tensor panel.

Is there a way to have a simpler implementation by creating a precision_update function, or is there an existing function that already does this?

Thank.

+4
source share
1 answer

You can replace use with a tf.contrib.metrics.streaming_accuracylower level tf.metrics.mean, which, incidentally, is ultimately used streaming_accuracy- you will find similarities in your respective documents.

eg. (not verified)

tf.metrics.mean(tf.nn.in_top_k(predictions=predictions, targets=labels, k=5))
+4
source

Source: https://habr.com/ru/post/1680290/


All Articles