在 keras 文档中,函数 keras.activations.relu(x, alpha=0.0, max_value=None, Threshold=0.0)
定义为:
f(x) = max_value for x >= max_value,
f(x) = x for threshold <= x < max_value,
f(x) = alpha * (x - threshold) otherwise.
我用 alpha=0.01
、threshold=5.0
和 max_value=100.0
以及 x=5.0< 做了一个小测试
我得到的输出是 f(x)=0.0
。
如果我没记错的话,由于x ==阈值
,我应该得到f(x)=x=5.0
。
谁能解释一下吗?
谢谢
- 朱利安
最佳答案
源代码中的文档是错误的。 (您应该转向 tf.keras 而不是 keras)。应该是,
f(x) = max_value for x >= max_value,
--> f(x) = x for threshold < x < max_value,
f(x) = alpha * (x - threshold) otherwise.
因此,当您的 x
== threshold
时,它会进入第三种情况,其中有 0
(即 x -阈值
)。这就是为什么您得到 0
。
如果您需要记录的行为 this line需要更改为,
x = x * tf.cast(tf.greater_equal(x, 阈值), floatx())
关于python - keras ReLU 层的意外输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59621943/