簡體   English   中英

Keras:如何創建自定義的Noisy Relu函數?

[英]Keras: How to create a custom Noisy Relu function?

如何在Keras中創建嘈雜的Relu函數? 特別是如何創建噪聲Y〜N(0,1)。

def relu_noise(x):
return x*(x>0) + N(0,1)

有任何想法嗎? 謝謝!

您可以將Lambda圖層用於該任務。

通常定義一個函數,但是使用keras后端函數:

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層中使用它:

from keras.layers import *

layer = Lambda(relu_noise, output_shape=(shape of x))

將此圖層與其他任何圖層一樣添加到Sequential模型中,或使用Model的輸入進行調用。

您可能還可以直接將其用作激活功能:

layer = Dense(units, activation=relu_noise)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM