Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Tensorflow 损失函数:平均成对平方误差_Tensorflow - Fatal编程技术网

Tensorflow 损失函数:平均成对平方误差

Tensorflow 损失函数:平均成对平方误差,tensorflow,Tensorflow,当我使用 tf.losses.mean_pairwise_squared_error(labels, predictions, weights=1.0, scope=None, loss_collection=tf.GraphKeys.LOSSES) 函数,我确信数据是正确的。然而,张力板上的损耗始终为零。我努力想弄清楚,但不知道为什么?下面是我代码的一部分。我用错形状了吗 score_a=tf.reshape(score,[-1])#shape: [1,39] ys_a=tf.reshape

当我使用

tf.losses.mean_pairwise_squared_error(labels, predictions, weights=1.0, scope=None, loss_collection=tf.GraphKeys.LOSSES)
函数,我确信数据是正确的。然而,张力板上的损耗始终为零。我努力想弄清楚,但不知道为什么?下面是我代码的一部分。我用错形状了吗

score_a=tf.reshape(score,[-1])#shape: [1,39]
ys_a=tf.reshape(ys,[-1])#shape: [1,39]
with tf.name_scope('loss'):
loss=tf.losses.mean_pairwise_squared_error(score_a,ys_a)

使用
tf.loss.mean_pairwise_squared_error()
标签
预测
应至少为2级,因为第一个维度将用作
批量大小
。这意味着您不需要重塑
score\u a
ys\u a
。(我假设
score_a
ys_a
有39个条目和一批。)

如果
标签
预测
为秩1,则意味着所有数据项均为0张量(标量),因此
tf.loss.mean_pairwise_squared_error()
的结果始终为零

还有一件事。在我看来,
tf.loss.mean\u pairwise\u squared\u error()
的当前实施(2018-01-03)看起来不完美。例如,如中所示,将以下数据作为
标签
预测

labels=tf.常数([[0,0.5,1.]]
预测=tf.常数([[1,1,1.]]
tf.损失。平均成对误差(标签、预测)
在这种情况下,结果应该是
[(0-0.5)^2+(0-1)^2+(0.5-1)^2]/3=0.5
,这与tensorflow得出的结果
0.3333333333 134651184
不同


[Update]tf.Loss.mean_pairwise_squared_error()中的错误(如上所述)已修复,并从tensorflow 1.6.0中应用。

如果您正在进行分类,则您可能会在一维中使用分类值标记
张量。如果是这种情况,则在调用
tf.loss.mean\u pairwise\u squared\u error()
之前,需要执行一次热转换以匹配预测的形状。您不需要改变预测的形状

labels_a = tf.one_hot(labels, 2)