Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 什么';tf.math.reduce_mean和tf.keras.metrics.mean之间的区别是什么?_Python_Tensorflow_Machine Learning_Deep Learning - Fatal编程技术网

Python 什么';tf.math.reduce_mean和tf.keras.metrics.mean之间的区别是什么?

Python 什么';tf.math.reduce_mean和tf.keras.metrics.mean之间的区别是什么?,python,tensorflow,machine-learning,deep-learning,Python,Tensorflow,Machine Learning,Deep Learning,我不知道该用什么函数。他们看起来一样,做同样的工作。我知道tf.keras.metrics.Mean是metric,但我不能在其他地方使用它吗?tf.keras.metrics.Mean和tf.math.reduce\u Mean的功能略有不同。 看看这个例子 #tf.keras.metrics.Mean:案例1 import tensorflow as tf x = tf.constant([[1, 3, 5, 7],[1, 1, 0, 0]]) m = tf.keras.metrics.Me

我不知道该用什么函数。他们看起来一样,做同样的工作。我知道tf.keras.metrics.Mean是metric,但我不能在其他地方使用它吗?

tf.keras.metrics.Mean和tf.math.reduce\u Mean的功能略有不同。 看看这个例子

#tf.keras.metrics.Mean:案例1

import tensorflow as tf
x = tf.constant([[1, 3, 5, 7],[1, 1, 0, 0]])
m = tf.keras.metrics.Mean()
m.update_state(x)
m.result().numpy()
输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#tf.keras.metrics.Mean:案例2

m.reset_state()
m.update_state([1, 3, 5, 7], sample_weight=[1, 1, 0, 0])
m.result().numpy()
输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#tf.math.reduce_平均值

#案例1

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#案例2

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#案例3

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)

tf.math.reduce_mean
的情况下,您可以看到,当axis(numpy)为1时,它计算(1,3,5,7)和(1,1,0,0)之间的平均值,因此1定义了计算平均值的轴。当它为0时,平均值通过(1,1)、(3,1)、(5,0)和(7,0)等计算得出。

tf.keras.metrics.mean和tf.math.reduce\u mean的功能略有不同。 看看这个例子

#tf.keras.metrics.Mean:案例1

import tensorflow as tf
x = tf.constant([[1, 3, 5, 7],[1, 1, 0, 0]])
m = tf.keras.metrics.Mean()
m.update_state(x)
m.result().numpy()
输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#tf.keras.metrics.Mean:案例2

m.reset_state()
m.update_state([1, 3, 5, 7], sample_weight=[1, 1, 0, 0])
m.result().numpy()
输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#tf.math.reduce_平均值

#案例1

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#案例2

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
#案例3

输出:

1.886
2.0
tf.Tensor(2, shape=(), dtype=int32)
tf.Tensor([4 0], shape=(2,), dtype=int32)
tf.Tensor([1 2 2 3], shape=(4,), dtype=int32)
tf.math.reduce_mean
的情况下,您可以看到,当axis(numpy)为1时,它计算(1,3,5,7)和(1,1,0,0)之间的平均值,因此1定义了计算平均值的轴。当它为0时,计算(1,1)、(3,1)、(5,0)和(7,0)的平均值,依此类推