Tensorflow中的微分圆形函数?

ron*_*123 5 python tensorflow

因此,我网络的输出是一个概率列表,然后我使用tf.round()将其取整为0或1,这对于该项目至关重要。然后我发现tf.round不可区分,所以我有点迷路了..:/

小智 10

您可以使用以下事实:tf.maximum()和tf.minimum()是可微的,并且输入是从0到1的概率

# round numbers less than 0.5 to zero;
# by making them negative and taking the maximum with 0
differentiable_round = tf.maximum(x-0.499,0)
# scale the remaining numbers (0 to 0.5) to greater than 1
# the other half (zeros) is not affected by multiplication
differentiable_round = differentiable_round * 10000
# take the minimum with 1
differentiable_round = tf.minimum(differentiable_round, 1)
Run Code Online (Sandbox Code Playgroud)

例:

[0.1,       0.5,     0.7]
[-0.0989, 0.001, 0.20099] # x - 0.499
[0,       0.001, 0.20099] # max(x-0.499, 0)
[0,          10,  2009.9] # max(x-0.499, 0) * 10000
[0,         1.0,     1.0] # min(max(x-0.499, 0) * 10000, 1)
Run Code Online (Sandbox Code Playgroud)


Tia*_*ana 10

类似于x-sin(2pi x)/(2pi)的东西吗?

我敢肯定有一种方法可以将斜坡压得更陡一些。

在此处输入图片说明

  • 这是一个被低估的答案。真诚的-一个需要所有现实的人;不只是[0,1] (4认同)

use*_*651 7

这对我有用:

x_rounded_NOT_differentiable = tf.round(x)
x_rounded_differentiable = x - tf.stop_gradient(x - x_rounded_NOT_differentiable)
Run Code Online (Sandbox Code Playgroud)


小智 4

舍入本质上是一个不可微的函数,所以你运气不好。这种情况的正常程序是找到一种方法来使用概率,例如使用它们来计算期望值,或者采用输出的最大概率并选择该概率作为网络的预测。如果您不使用输出来计算损失函数,您可以继续将其应用于结果,并且它是否可微分并不重要。现在,如果您想要一个信息丰富的损失函数来训练网络,也许您应该考虑将输出保持为概率格式是否实际上对您有利(它可能会使您的训练过程更加顺利) - 这样您就可以训练后可以将概率转换为网络外部的实际估计。