<p>I was doing a task using RNN to predict a time series movement.</p>
<p>I want to make my results reproducible. So I strictly followed this post:
<a href="https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras">https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras</a></p>
<p>My code are as follows:</p>
<pre><code># 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
os.environ['PYTHONHASHSEED']=str(seed_value)

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

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

tf.compat.v1.set_random_seed(seed_value)

tf.random.set_seed(seed_value)

# 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)
tf.compat.v1.keras.backend.set_session(sess)
</code></pre>
<p>However, every time I ran my codes, I still got a different result, what could the reasons be?</p>

CC BY-SA 4.0
2022-06-22T15:19:55.547Z
This question seems to be off-topic (please read the [rules](https://ai.stackexchange.com/help/on-topic)). Consider asking programming questions on StackOverflow.
Aray Karjauv
CC BY-SA 4.0
2022-06-22T15:24:40.580Z
@ArayKarjauv I don't think this is a programming question, but OK.
user900476
CC BY-SA 4.0
2022-06-22T19:14:44.817Z
FYI If using GPU, non-random reproducibility is more complicated than that because of random results ordering.
Julian Moore
<deep-learning><recurrent-neural-networks><tensorflow><keras><time-series>
Why can't I reproduce my results in keras using random seed?
user900476
# Why can't I reproduce my results in keras using random seed?

(Asked by: username_0 on 2022-06-22)

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
os.environ['PYTHONHASHSEED']=str(seed_value)

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

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

tf.compat.v1.set_random_seed(seed_value)

tf.random.set_seed(seed_value)

# 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)
tf.compat.v1.keras.backend.set_session(sess)

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

**Tags:** deep-learning, recurrent-neural-networks, tensorflow, keras, time-series

> **Comments:**
> **username_1**: This question seems to be off-topic (please read the [rules](https://ai.stackexchange.com/help/on-topic)). Consider asking programming questions on StackOverflow.  
> **username_0**: @ArayKarjauv I don't think this is a programming question, but OK.  
> **username_2**: FYI If using GPU, non-random reproducibility is more complicated than that because of random results ordering.  

---

## 0 answers

