2

I am using Keras == 1.1.0 and tensorflow-gpu == 1.12.0.
The error is called after:

    input_layer = Input(shape=(2, ))
    layer = Dense(self._hidden[0], activation='relu')(input_layer)

and this is the Traceback

Traceback (most recent call last):
  File "D:/Documents/PycharmProjects/DDPG-master-2/main.py", line 18, in <module>
    main()
  File "D:/Documents/PycharmProjects/DDPG-master-2/main.py", line 14, in main
    agent = Agent(state_size=world.state_size, action_size=world.action_size)
  File "D:\Documents\PycharmProjects\DDPG-master-2\ddpg.py", line 50, in __init__
    batch_size=batch_size, tau=tau)
  File "D:\Documents\PycharmProjects\DDPG-master-2\networks\actor.py", line 68, in __init__
    self._generate_model()
  File "D:\Documents\PycharmProjects\DDPG-master-2\networks\actor.py", line 132, in _generate_model
    layer = Dense(self._hidden[0], activation='relu')(input_layer)
  File "D:\Anaconda3\lib\site-packages\keras\engine\topology.py", line 487, in __call__
    self.build(input_shapes[0])
  File "D:\Anaconda3\lib\site-packages\keras\layers\core.py", line 695, in build
    name='{}_W'.format(self.name))
  File "D:\Anaconda3\lib\site-packages\keras\initializations.py", line 59, in glorot_uniform
    return uniform(shape, s, name=name)
  File "D:\Anaconda3\lib\site-packages\keras\initializations.py", line 32, in uniform
    return K.random_uniform_variable(shape, -scale, scale, name=name)
  File "D:\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 282, in random_uniform_variable
    return variable(value, dtype=dtype, name=name)
  File "D:\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 152, in variable
    if tf.get_default_graph() is get_session().graph:
AttributeError: 'function' object has no attribute 'graph'

Process finished with exit code 1

I previously had tensorflow-gpu == 1.9 and uninstalled it and upgraded to 1.12, as I saw that it was a common solutions for similar problems. It did not work though.

EDIT (adding some relevant code related to the Traceback):

   agent = DDPG(state_size=world.state_size, action_size=world.action_size)

   self._actor = Actor(tensorflow_session=tensorflow_session,
                            state_size=state_size, action_size=action_size,
                            hidden_units=actor_hidden_units,
                            learning_rate=actor_learning_rate,
                            batch_size=batch_size, tau=tau)

       def _generate_model(self):
        """
        Generates the model based on the hyperparameters defined in the
        constructor.

        :return: at tuple containing references to the model, weights,
            and input later
        """
        input_layer = Input(shape=(self._state_size,))
        layer = Dense(self._hidden[0], activation='relu')(input_layer)
        layer = Dense(self._hidden[1], activation='relu')(layer)
        output_layer = Dense(self._action_size, activation='sigmoid')(layer)
        model = Model(input=input_layer, output=output_layer)
        return model, model.trainable_weights, input_layer

The code is related to three different classes.

3
  • Can you please put some relevant code? I guess it is related to imported packages. Commented Jan 14, 2019 at 11:04
  • Hi Amir, as relevant code I guess you mean the parts related to the Traceback? I'll put that right now Commented Jan 14, 2019 at 11:07
  • I run the model it throws an exception. Changing input & output in Model() to inputs & outputs fix the issue. The rest of the code is just fine. Commented Jan 14, 2019 at 11:21

2 Answers 2

1

I experienced the same issue. Here are the things I did to resolve it:

  1. Make sure that there is no other files in my project named tensorflow.py
  2. re-install tensorflow with --no-cache-dir argument pip --no-cache-dir install tensorflow and removed pip cache files.

    For linux:
    rm -rf ~/.cache/pip/*

    For windows, delete the files in this location: %LocalAppData%\pip\Cache

I hope this helps

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

1 Comment

Hi John, thanks, I tried but unfortunately it doesn't work. Since the last line of the Traceback is this lib\site-packages\keras\backend\tensorflow_backend.py, it might be keras instead of tensorflow?
0

Here is how I solved the issue.

1. Uninstall keras with pip uninstall keras
2. Check that no other versions were installed (for example through conda)
3. Delete the cache in %LocalAppData%\pip\Cache
4. Re-install keras

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.