6

when I use 'import talos' I get the following error:

Traceback (most recent call last):
  File "C:/Users/Mirijam/Desktop/rp/RNN_classification/classification.py", line 4, in <module>
    import talos
  File "C:\Users\Mirijam\Desktop\rp\venv\lib\site-packages\talos\__init__.py", line 14, in <module>
    from . import utils
  File "C:\Users\Mirijam\Desktop\rp\venv\lib\site-packages\talos\utils\__init__.py", line 11, in <module>
    from .sequence_generator import SequenceGenerator
  File "C:\Users\Mirijam\Desktop\rp\venv\lib\site-packages\talos\utils\sequence_generator.py", line 1, in <module>
    from keras.utils import Sequence
ImportError: cannot import name 'Sequence' from 'keras.utils' (C:\Users\Mirijam\Desktop\rp\venv\lib\site-packages\keras\utils\__init__.py)

My keras version is 2.5.0. My other Keras imports seems to be working.

1 Answers1

7

I was able to replicate your issue, you can refer working code as shown below

import talos
import keras

print(talos.__version__)
print(keras.__version__)

from keras.utils import Sequence 

Output:

1.0.0
2.5.0

ImportError                               Traceback (most recent call last)
<ipython-input-14-064232ea7706> in <module>()
----> 1 from keras.utils import Sequence # it wont work

ImportError: cannot import name 'Sequence' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)

Fixed code:

From Tensorflow 2.x onward, keras is no longer maintained and it became a part of Tensorflow. I would recommend instead of import Sequence from keras, you should try from tensorflow as shown below

from tensorflow.keras.utils import Sequence

For more information you can refer here.

  • In my case the error still persisted and I needed to uninstall and reinstall keras accordingly to the tensorflow version. Then the solution proposed here worked fine, even if my editor says that `tensorflow.keras.utils` can not be resolved. – Aelius Jun 09 '22 at 15:35