Using tf.random.set_seed but still getting an error no attribute 'set_random_seed'

73 views Asked by At

I'm trying to set seed using tf.random.set_seed instead of tf.set_random_seed, but still getting the error as module 'tensorflow' has no attribute 'set_random_seed'

Trying to run this:

def __init__(self, log_name, heatmap_size, image_size, loss_type = 'SCE', is_training = True):
        tf.random.set_seed(0)

But getting the error:

28
29 
def __init__(self, log_name, heatmap_size, image_size, loss_type = 'SCE', is_training = True):
---> 30         tf.random.set_seed(0)
     31 
     32         if loss_type not in { 'MSE', 'SCE' }:

AttributeError: module 'tensorflow' has no attribute 'set_random_seed'
1

There are 1 answers

2
Talha Tayyab On BEST ANSWER

For Tensorflow 2.15 you can use:

tf.keras.utils.set_random_seed(
    seed
)

Link to document : https://www.tensorflow.org/api_docs/python/tf/keras/utils/set_random_seed