简体   繁体   English

可重复结果的种子不起作用(Tensorflow)

[英]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.

相关问题 使用 tf.set_random_seed 在 Tensorflow 中可重现结果 - Reproducible results in Tensorflow with tf.set_random_seed 获得可重复结果的问题,设置种子 Tensorflow object 检测 API - Problem with getting reproducible results, set seed Tensorflow object detection API Tensorflow:Tensordot可重现的结果 - Tensorflow: Tensordot reproducible results 在 Python 中使用 Keras 和 TensorFlow 无法重现结果 - Results not reproducible with Keras and TensorFlow in Python 如何在CNN模型中使用tensorflow-gpu获得可重现的结果? - How to get reproducible results using tensorflow-gpu in CNN model? 没有得到可重复的结果 TensorFlow-Keras-Google 协作 - Not getting reproducible results TensorFlow-Keras-Google Collab Tensorflow 1.8.0:宽和深模型结果不稳定。 随机种子不起作用 - Tensorflow 1.8.0: Wide and Deep Model results are not stable. Random seed is not working Tensorflow:具有相同随机种子的不同结果 - Tensorflow: Different results with the same random seed 即使使用随机种子,也无法使用 Tensorflow 重现结果 - Not able to reproduce results with Tensorflow even with random seed 即使设置了种子值也无法再现结果(Microsoft CNTK的Python API) - Non Reproducible results even after setting the seed value (Python API of Microsoft CNTK)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM