!pip install tensorflow==1.15 #Make sure you have updated the Tensorflow version for tf.metrics.average_precision_at_k to work
y_true = np.array([[2], [1], [0], [3], [0]]).astype(np.int64)
y_true = tf.identity(y_true)
y_pred = np.array([[0.1, 0.2, 0.6, 0.1],
y_pred = tf.identity(y_pred)
_, m_ap = tf.metrics.average_precision_at_k(y_true, y_pred, 3)
sess.run(tf.local_variables_initializer())
stream_vars = [i for i in tf.local_variables()]
print((sess.run(stream_vars)))
tmp_rank = tf.nn.top_k(y_pred,3)
print(sess.run(tmp_rank))