查看: 1353|回复: 0

如何使用TensorFlow获得稳定的结果,设置随机种子

[复制链接]

27

主题

37

帖子

116

积分

论坛管理

Rank: 4

积分
116
发表于 2018-10-13 17:37:07 | 显示全部楼层 |阅读模式
I'm trying to run a neural network multiple times with different parameters in order to calibrate the networks parameters (dropout probabilities, learning rate e.d.). However I am having the problem that running the network while keeping the parameters the same still gives me a different solution


解决办法:
设置当前TensorFlow随机种子仅影响当前默认图形。由于您要为训练创建新图并将其设置为默认值(使用g.as_default(),因此必须使用块设置随机种子。 例如,循环应如下所示:



  1. for i in range(3):
  2.   g = tf.Graph()
  3.   with g.as_default():
  4.     tf.set_random_seed(1)
  5.     accuracy_result, average_error = network.train_network(
  6.         parameters, inputHeight, inputWidth, inputChannels, outputClasses)
复制代码
请注意,这将对外部for循环的每次迭代使用相同的随机种子。如果要在每次迭代中使用不同但仍然确定的种子,可以使用tf.set_random_seed(i + 1)。






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表