Good day,
Here is the error. Can somebody help how can i solve it?
ImportError Traceback (most recent call last)
<ipython-input-18-c29f17706012> in <module>
7 import numpy as np
8 import numpy.random as nr
----> 9 from tensorflow import set_random_seed
10 import matplotlib.pyplot as plt
11 get_ipython().run_line_magic('matplotlib', 'inline')
ImportError: cannot import name 'set_random_seed' from 'tensorflow' (C:\Users\polon\Anaconda3\lib\site-packages\tensorflow\__init__.py)
Looked for similar problems on Stack, but nothing worked for me.
In Tensoflow2 there is no need to perform
from tensorflow import set_random_seed
in order to run
set_random_seed(x)
(as it was in older version)
Only have to run
import tensorflow
tensorflow.random.set_seed(x)
Thanks to @David Buck
I too faced same error but instead of from tensorflow import set_random_seed
, I've used
import tensorflow as tf
tf.random.set_seed()
And it worked I think that method is useful for version 1 and the above snippet is useful for version 2
TensorFlow API has been updated from set_random_seed() to set_seed()
You can use the following code:
from tensorflow.random import set_seed
Reference Link:
This code works for me:
from numpy.random import seed
seed(1)
from tensorflow import random
random.set_seed(1)
I got the same result of my neural network model every time.
You want to use the random seed number.
You can try with this
import tensorflow as tf
tf.set_random_seed(1234)
you can also try the following import statement
from tensorflow.python.framework.random_seed import set_random_seed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.