def evaluationTok_k(k=3):
prediction =tf.nn.in_top_k(model,tf.argmax(Y,1),k=k)
accuracy =tf.reduce_mean(tf.cast(prediction,'float32'))
is_top1 =tf.equal(tf.nn.top_k(model,k)[1][:,0],tf.cast(tf.argmax(Y,1),'int32'))
is_top2 = tf.equal(tf.nn.top_k(model, k)[1][:, 1], tf.cast(tf.argmax(Y, 1), 'int32'))
is_top3 = tf.equal(tf.nn.top_k(model, k)[1][:, 2], tf.cast(tf.argmax(Y, 1), 'int32'))
is_in_top1 =is_top1
is_in_top2 = tf.logical_or(is_in_top1, is_top2)
is_in_top3 = tf.logical_or(is_in_top2, is_top3)
accuracy11 = tf.reduce_mean(tf.cast(is_in_top1, "float32"))
accuracy22 = tf.reduce_mean(tf.cast(is_in_top2, "float32"))
accuracy33 = tf.reduce_mean(tf.cast(is_in_top3, "float32"))
return accuracy
top_K-evalon_minist.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录