tensorflow_core._api.v2.random has no attribute Generator

Viewed 4144

I am seeing the following error when I try to import tensorflow_addons with tensorflow 2.1

> import tensorflow_addons as tfa
AttributeError: module 'tensorflow_core._api.v2.random' has no attribute 'Generator'
3 Answers

There is an incompability between your Tensorflow and Tensorflow-addons versions. To solve your problem, uninstall your current version and replace it with the right one which you can get by checking this table

A little reminder: To check your Tensorflow version type in terminal:

python -c 'import tensorflow as tf; print(tf.__version__)'

I was able to fix this by patching tf.random.Generator

import tensorflow as tf
tf.random.Generator = None  # Patch for a bug
import tensorflow_addons as tfa

Check your tensorflow version -

import tensorflow as tf
print(tf.__version__)

Check the corresponding tf-addons version here

Uninstall the previous version and install the correct one -

pip uninstall tensorflow-addons
pip install tensorflow-addons==[version-number]

Eg - pip install tensorflow-addons==0.9.1 for tensorflow version 2.1.0

Related