2017-09-05 66 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初始化器? –

相关问题