2017-09-05 54 views
2

我使用Keras Sequential模型,其中輸入和標籤每次運行完全相同。 Keras正在使用Tensorflow後端。我可以以確定性的方式進行Keras培訓嗎?

我在訓練過程中將圖層激活設置爲「零」並禁用批次洗牌。

model = Sequential() 
model.add(Dense(128, 
       activation='relu', 
       kernel_initializer='zeros', 
       bias_initializer='zeros')) 
... 

model.compile(optimizer='rmsprop', loss='binary_crossentropy') 

model.fit(x_train, y_train, 
      batch_size = 128, verbose = 1, epochs = 200, 
      validation_data=(x_validation, y_validation), 
      shuffle=False) 

我也試過播種與NumPy的random()方法:

np.random.seed(7) # fix random seed for reproducibility 

有了上面的訓練結束後,我還會收到不同的精度和損耗值。

我是否錯過了一些東西,或者有沒有辦法完全消除培訓之間的差異?

+1

[也許有關](https://github.com/fchollet/keras/issues/2280) – sascha

+0

謝謝 - 是的,這是一個已知/開放的問題。 – RobertJoseph

回答

1

因爲這似乎是一個real issue,因爲之前評論說,也許你可以去手動初始化的權重(而不是信任「零」參數在層構造通過):

#where you see layers[0], it's possible that the correct layer is layers[1] - I can't test at this moment. 

weights = model.layers[0].get_weights() 
ws = np.zeros(weights[0].shape) 
bs = np.zeros(weights[1].shape) 
model.layers[0].set_weights([ws,bs]) 
+1

這個想法正是爲了避免那些傳遞參數。在numpy中,我們相信,但我們是否相信考慮鏈接中的問題的keras初始化器? –

相關問題