【问题标题】:Unexpected output for keras ReLU layerkeras ReLU 层的意外输出
【发布时间】:2020-01-07 03:52:37
【问题描述】:

在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.01threshold=5.0max_value=100.0 做了一个小测试,对于x=5.0,我得到的输出是f(x)=0.0

如果我没记错的话,既然x == threshold,我应该得到f(x)=x=5.0

谁能解释一下?

谢谢,

  • 朱利安

【问题讨论】:

  • 请编辑您的问题,而不是发布详细信息作为答案。事情会清楚得多。

标签: python keras threshold relu


【解决方案1】:

源代码中的文档有误。 (你应该转移到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 - threshold)。这就是你得到0的原因。

如果您需要记录 this line 的行为需要更改为,

x = x * tf.cast(tf.greater_equal(x, threshold), floatx())

【讨论】:

  • 我自己在tensorflow中找不到ReLU代码...非常感谢!!
猜你喜欢
  • 2022-01-15
  • 1970-01-01
  • 2013-04-26
  • 2022-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2017-07-14
相关资源
最近更新 更多