[英]Seed for reproducible results is not working (Tensorflow)
I'm having a problem that concern the reproducibility of my results using Tensorflow (v1.15.3).我遇到的问题涉及使用 Tensorflow (v1.15.3) 的结果的可重复性。 I set all the seeds (os, random, numpy and tensorflow) but the results of a convolutional neural networks changes always between executions (even if similar).我设置了所有种子(操作系统、随机、numpy 和 tensorflow),但卷积神经网络的结果总是在执行之间发生变化(即使相似)。
I set my seeds in this way:我以这种方式设置我的种子:
seed_value = 1234
import os
os.environ['PYTHONHASHSEED'] = str(seed_value)
import random
random.seed(seed_value)
import numpy as np
np.random.seed(seed_value)
import tensorflow as tf
tf.compat.v1.set_random_seed(seed_value)
tf.set_random_seed(seed_value)
Next I define the weights of the net like this:接下来,我像这样定义网络的权重:
weights = {
'conv1/conv2d': tf.get_variable('conv1/weights', shape=[3,3,512,1024], initializer=tf.contrib.layers.xavier_initializer()),
# and more ...
}
(things doesn't change if I use or not the initializer for the weights) (如果我使用或不使用权重初始化器,事情不会改变)
after that I define the graph with convolution operations using the weights initialised before (I omit that because there is no way to set seed to the tf.nn.conv2d operation in Tensorflow and because only the weights are the dynamic part of the model that could affect the results).之后,我使用之前初始化的权重定义具有卷积操作的图形(我省略了这一点,因为没有办法将种子设置为 Tensorflow 中的 tf.nn.conv2d 操作,并且因为只有权重是 model 的动态部分,可以影响结果)。
Any idea how to get always the same results after defining a model in this way using Tensorflow?知道如何使用 Tensorflow 以这种方式定义 model 后始终获得相同的结果吗?
Thank you.谢谢你。
I suggest, after我建议,之后
weights = {
'conv1/conv2d': tf.get_variable('conv1/weights', shape=[3,3,512,1024], initializer=tf.contrib.layers.xavier_initializer()),
# and more ...
}
store the weight externally in a file, for example, then next time you run, do not go through that previous line and load the weight from the external file.例如,将权重存储在外部文件中,然后下次运行时,不要通过上一行 go 并从外部文件加载权重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.