Tensorflow随机种子不起作用

时间:2018-01-13 02:50:56

标签: python random tensorflow random-seed

我的项目中有以下代码段

import numpy as np
np.random.seed(1337)  # for reproducibility
import tensorflow as tf
tf.set_random_seed(1)

  # Here are the dictionary of weights and biases of each layer
        weights = {
            'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1], stddev=STDDEV, seed=1)),
            'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2], stddev=STDDEV, seed=1)),
        }

        biases = {
            'b1': tf.Variable(tf.random_normal([n_hidden_1], seed=1)),
            'b2': tf.Variable(tf.random_normal([n_hidden_2], seed=1))
        }

 init_op = tf.global_variables_initializer()
    # Launch session
    sess = tf.Session()
    sess.run(init_op)

        for i in range(total_batch):
            randidx = np.random.randint(int(TRAIN_SIZE), size=BATCH_SIZE)
            batch_xs = data_train[randidx, :]
            batch_ys = labels_train[randidx, :]
            # Fit using batched data
            sess.run(optimizer, feed_dict={X: batch_xs, y: batch_ys, dropout_keep_prob: 0.9})
            # Calculate average cost
            avg_cost += sess.run(cost, feed_dict={X: batch_xs, y: batch_ys, dropout_keep_prob: 1.}) / total_batch

正如您所看到的,我在顶部设置了随机设置,每次运行此代码时都会产生不同的结果。为什么我的随机种子不起作用。

0 个答案:

没有答案