1

I tried to get following program to work: https://github.com/mattdangerw/keras-text-generation

In my CMD (Windows 10) I entered:

python train.py

I got following error:

Using TensorFlow backend.
Loading data...
corpus length: 1223047
vocab size: 41
x.shape: (44608, 50)
y.shape: (44608, 50, 1)
x_val.shape: (4288, 50)
y_val.shape: (4288, 50, 1)
Data load time 0.958162784576416
Building model...
Traceback (most recent call last):
File "train.py", line 42, in <module>
    main()
File "train.py", line 37, in main
    model.train(**vars(args))
File "D:\IoT\Aufgabe4\task3\keras-text-generation\model.py", line 135, in train
    self._build_models(batch_size, embedding_size, rnn_size, num_layers)
File "D:\IoT\Aufgabe4\task3\keras-text-generation\model.py", line 92, in _build_models
    model = Sequential()
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\sequential.py", line 87, in __init__
    super(Sequential, self).__init__(name=name)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 96, in __init__
    self._init_subclassed_network(**kwargs)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 294, in _init_subclassed_network
    self._base_init(name=name)
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\engine\network.py", line 109, in _base_init
    name = prefix + '_' + str(K.get_uid(prefix))
File "C:\Users\Michael\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 74, in get_uid
    graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

Python Version:

python --version
    Python 3.7.3

Keras Version:

python -c "import keras; print(keras.__version__)"
    Using TensorFlow backend.
    2.2.4

Tensorflow Version:

python -c "import tensorflow as tf; print(tf.__version__)"
    2.0.0-alpha0

I also installed pip and with pip I have also installed colorama, which is needed.

How to fix it? A friend tested the same program and performed the same installation and configuration, but without any error messages. I think it`s a problem with tensorflow. Am I right?

1
  • 2
    try this from tensorflow.python.keras import backend as k Commented May 22, 2019 at 12:56

2 Answers 2

1

Keras does not currently support TensorFlow 2.0, since it is still an alpha version. You either need to use tf.keras, or downgrade TensorFlow to 1.13 in order to use the official keras package.

Sign up to request clarification or add additional context in comments.

1 Comment

The solution was to uninstall with pip uninstall keras and pip uninstall tensorflow. After that I installed with pip install tensorflow==1.130rc1 and pip install keras==2.0.0 the "right working" versions
0

This is a known Tensorflow/Keras bug, read more here:

https://github.com/keras-team/keras/issues/12379

Solution as per link (same as in comment by @Vishal):

I changed the imports from keras.something.something to tensorflow.keras.something and the issue seemed to have gone away. Putting it here for others to benefit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.