[英]Set starting weights individually for neural network
我有一個簡單的前饋神經網絡,由 8 個輸入神經元組成,然后是 2 個隱藏層,每個隱藏層有 6 個隱藏神經元和 1 個 output 層,由 1 個 output 神經元組成。
Keras 代碼為:
model = Sequential()
model.add(Dense(6, input_dim = 8, activation='tanh')
model.add(Dense(6, activation='tanh'))
model.add(Dense(1, activation='tanh'))
問題:
由於我知道 8 個輸入參數中的哪一個對單個 output 影響最大,因此我可以將它們的起始權重設置為相對於其他輸入參數更高的值。 如果這可能會顯着減少培訓時間(如果我沒有錯的話)。
# reading the initial weights and bias of the input layer
layer_1 = (model.layers)[0]
# reading the initial weights of the input layer
w_1 = layer_1.get_weights()[0]
# setting weights for nth parameter of the input layer to a modified value val
w_1[n, :] = val
# setting the modified weights and unmodified bias of the input layer
layer_1.set_weights([w_1, layer_1.get_weights()[1]])
# writing layer_1 to model
(model.layers)[0] = layer_1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.