tf.equal(x, y)
判断x, y是否相等,相等返回true,不相等false
假设x为预测的结果,y为正确的标签值。
import tensorflow as tf
x = [1, 3, 0, 2]
y = [1, 4, 2, 2]
equal = tf.equal(x, y)
with tf.Session() as sess:
print(sess.run(equal))
>>[ True False False True]
tf.cast(x, dtype, name=None)
数据类型转换
- x:待转换的数据
- dtype:目标数据类型
- name=None:操作的名称
import tensorflow as tf
x = [1, 3, 0, 2]
y = [1, 4, 2, 2]
equal = tf.equal(x, y)
type = tf.cast(equal, tf.float32)
with tf.Session() as sess:
print(sess.run(type))
->[1. 0. 0. 1.]
tf.reduce_mean()
print(sess.run(tf.reduce_mean(type)))
->0.5
tf.argmax(input, axis=None, name=None, dimension=None)
此函数是对矩阵按行或列计算最大值,输出最大值的下标
参数
input:输入Tensor
axis:0表示按列,1表示按行
name:名称
dimension:和axis功能一样,默认axis取值优先。新加的字段
返回:Tensor 一般是行或列的最大值下标向量.
[参考]
(https://blog.csdn.net/duanlianvip/article/details/93642311)