![](/img/trans.png)
[英]Implementing a custom loss function in Keras with a term like l1 regularisation
[英]Different coefficients for L1-L2 regularisation
我想用L1和L2正則化來規范網絡的權重。 但是,我無法找到一種獨立改變規則強度的方法。 Keras 文檔也沒有提供任何信息。
那么, 有沒有辦法在l1_l2
常規器中使用不同的優勢? 或者也許是另一種獲得相同結果的方法?
我目前的模型很簡單:
stren = 0.001
model = Sequential()
model.add(Dense(64, input_dim=148, activation='relu', kernel_regularizer=reg.l2(stren)))
model.add(Dense(1, activation='sigmoid', kernel_regularizer=reg.l2(stren)))
而且我希望能夠擁有以下內容:
kernel_regularizer=reg.l1_l2(l1_str, l2_str)
當然,您可以獨立改變正規化器的優勢:
from keras import regularizers
regularizers.l1_l2(l1=0.001, l2=0.1) # the strength of l1 is set to 0.001 and l2 to 0.1
也許您可以嘗試根據損失函數自定義正則化,並在Keras框架中設計用戶定義的正則化函數。 像這樣的東西:
def l1_l2(l1=0.01, l2=0.01):
return L1L2(l1=l1, l2=l2)
或者使用Dropout(0.2)
等層之間的dropout函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.