tf pit in tf.metrics

Author: know almost Users
link: https: //www.zhihu.com/question/277184041/answer/480219663

PPT which first data in one picture, I feel very image. Saw this picture, I counted about understanding the AP calculation.

AP and precision for different reasons is the AP considers the recall factor, I understand the AP concept is a recommendation within the same system for different (0.10--1.00) recall value recorded a corresponding precision, and then calculate all recall value corresponds precision average. FIG on the AP value is the precision of the gray portion 10 and divided by 10 to obtain the final result 0.76.

MAP of computing, I see this picture, just a little bit to understand.

Pull a bunch of, say back tf.metrics.sparse_average_precision_at_k, go Github find this function on a moment, and then found in the new version, in fact, it is the use of average_precision_at_kthis function, then its main parameters are as follows:

labels, predictions, k, weights, metrics_ collections, updates_collections, name

I think it is to focus on labels, predictions, k, give an example, the example I searched the whole Google, finally

Github's issue found.

import tensorflow as tf
import numpy as np y_true = np.array([[2], [1], [0], [3], [0], [1]]).astype(np.int64) y_true = tf.identity(y_true) y_pred = np.array([[0.1, 0.2, 0.6, 0.1], [0.8, 0.05, 0.1, 0.05], [0.3, 0.4, 0.1, 0.2], [0.6, 0.25, 0.1, 0.05], [0.1, 0.2, 0.6, 0.1], [0.9, 0.0, 0.03, 0.07]]).astype(np.float32) y_pred = tf.identity(y_pred) _, m_ap = tf.metrics.sparse_average_precision_at_k(y_true, y_pred, 2) sess = tf.Session() sess.run(tf.local_variables_initializer()) stream_vars = [i for i in tf.local_variables()] print((sess.run(stream_vars))) tf_map = sess.run(m_ap) print(tf_map) tmp_rank = tf.nn.top_k(y_pred,4) print(sess.run(tmp_rank))
  1. Briefly, the first y_truerepresentative of a label value (not through Hot-One) , shape:(batch_size, num_labels) , y_predon behalf of the predicted value (logit value),shape:(batch_size, num_classes)
  2. Secondly, we must note that tf.metrics.sparse_average_precision_at_kwill be adopted top_kaccording to different kvalues y_predsorting operation, it tmp_rankis to help understand what the big Karma y_predwas kind of conversion function.
  3. Then, stream_vars = [i for i in tf.local_variables()]this line is to help understand the big Karma tf.metrics.sparse_average_precision_at_kcreated tf.local_varibles the actual output value, in turn, can better understand the usage of this function.
  4. See the specific example, when k=1the time, only the first batch of the tags and the predicted output is matched , the final output is: 1/6 = 0.166666; as k=2when, in addition to a first prediction of the batch output, the output of the third batch are predicted and label match, so the final output (1+(1/2))/6 = 0.25is: .

Guess you like

Origin www.cnblogs.com/walktosee/p/11005739.html
tf2