I was doing a task using RNN to predict a time series movement.

I want to make my results reproducible. So I strictly followed this post: https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras

My code are as follows:

# Seed value
# Apparently you may use different seed values at each stage
seed_value= 0

# 1. Set the `PYTHONHASHSEED` environment variable at a fixed value
import os

# 2. Set the `python` built-in pseudo-random generator at a fixed value
import random

# 3. Set the `numpy` pseudo-random generator at a fixed value
import numpy as np



# 5. Configure a new global `tensorflow` session

# for later versions:
session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)
sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)

However, every time I ran my codes, I still got a different result, what could the reasons be?


1 Answer 1


Are you using a CPU or a GPU?

If you are using a GPU, there is an additional source of randomness.

To confirm this point, you can try to use TensorFlow with CPU only, or disable Cuda DNN but the model will be twice longer:

THEANO_FLAGS="optimizer_excluding=conv_dnn" python your_file.py

THEANO_FLAGS="dnn.conv.algo_bwd_filter=deterministic,dnn.conv.algo_bwd_data=deterministic" python your_file.py

Source: https://github.com/keras-team/keras/issues/2479#issuecomment-213987747


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.