How to Fix AttributeError: Module ‘TensorFlow’ has no attribute ‘set_random_seed’

Module 'TensorFlow' has no attribute 'set_random_seed'

AttributeError: Module ‘TensorFlow’ has no attribute ‘set_random_seed’ error occurs when you try to “call the set_random_seed()” function on the TensorFlow version 2.x in which it does not exist.”

How to fix it?

To fix the AttributeError: Module ‘TensorFlow’ has no attribute ‘set_random_seed’ error, use the “tf.random.set_seed()” method if you are using TensorFlow version 2.x.

You can check your currently installed TensorFlow version using the below code:

import tensorflow as tf




Common causes of the error

  1. You are using an outdated version of TensorFlow. The set_random_seed() function was removed in TensorFlow 2.0.
  2. You are using a different module than TensorFlow. For example, you might be using the tensorflow.compat.v1 module, which still has the set_random_seed() function.
  3. You have made a typo in your code.

Alternate solutions

  1. Upgrade your installed tensorflow version to the latest version and use the “tf.random.set_seed()” function.
  2. You can try checking your code for typos.

I hope you will fix your error by following this article.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.