import tensorflow as tf
a= tf.constant([[0.1,0.2,0.],
[0.9,0.85,0.5]
])
求a每一行最大值的位置tf.argmax(),并转化为int32类型
pred=tf.cast(tf.argmax(a,axis=1),dtype=tf.int32)
y= tf.constant([2,1])
tf.equal(y,pred)
将bool类型转化为int32,并将所得结果相加
correct=tf.reduce_sum(tf.cast(tf.equal(y,pred),dtype=tf.int32))
print(correct/2)
机器学习笔记求输出的正确率
最新推荐文章于 2024-01-14 11:36:20 发布