2024-04-19 23:42:51 发布
网友
如何在Keras中创建嘈杂的Relu函数? 尤其是如何产生噪声Y~N(0,1)。在
def relu_noise(x): return x*(x>0) + N(0,1)
有什么想法吗?谢谢!在
您可以为该任务使用Lambda层。在
Lambda
通常定义函数,但使用keras backend函数:
def relu_noise(x): isPositive = K.greater(x,0) noise = K.random_normal((shape of x), mean=0.5, stddev=0.5) #I'm just not sure this is exactly the kind of noise you want. return (x * isPositive) + noise
然后在lambda层中使用它:
将此层添加到Sequential模型中作为任何其他层,或使用Model中的输入调用它。在
Sequential
Model
您也可以直接将其用作激活函数:
layer = Dense(units, activation=relu_noise)
您可以为该任务使用
Lambda
层。在通常定义函数,但使用keras backend函数:
然后在lambda层中使用它:
^{pr2}$将此层添加到
Sequential
模型中作为任何其他层,或使用Model
中的输入调用它。在您也可以直接将其用作激活函数:
相关问题 更多 >
编程相关推荐