3

I am trying to use Keras on my machine but I keep getting the error message "AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'".

Stack Trace is:

---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call last)
<ipython-input-1-dd13cebc6f04> in <module>
----> 1 import acgan

~/Documents/GitHub/Keras-GAN/acgan/acgan.py in <module>
  1 from __future__ import print_function, division
  2 
 ----> 3 from keras.datasets import mnist
  4 from keras.layers import Input, Dense, Reshape, Flatten, Dropout, multiply
  5 from keras.layers import BatchNormalization, Activation, Embedding, ZeroPadding2D

/anaconda3/lib/python3.6/site-packages/keras/__init__.py in <module>
  1 from __future__ import absolute_import
  2 
 ----> 3 from . import utils
  4 from . import activations
  5 from . import applications

/anaconda3/lib/python3.6/site-packages/keras/utils/__init__.py in <module>
  4 from . import data_utils
  5 from . import io_utils
 ----> 6 from . import conv_utils
  7 from . import losses_utils
  8 from . import metrics_utils

 /anaconda3/lib/python3.6/site-packages/keras/utils/conv_utils.py in <module>
  7 from six.moves import range
  8 import numpy as np
  ----> 9 from .. import backend as K
 10 
 11 

 /anaconda3/lib/python3.6/site-packages/keras/backend/__init__.py in <module>
 ----> 1 from .load_backend import epsilon
  2 from .load_backend import set_epsilon
  3 from .load_backend import floatx
  4 from .load_backend import set_floatx
  5 from .load_backend import cast_to_floatx

 /anaconda3/lib/python3.6/site-packages/keras/backend/load_backend.py in <module>
 88 elif _BACKEND == 'tensorflow':
 89     sys.stderr.write('Using TensorFlow backend.\n')
 ---> 90     from .tensorflow_backend import *
 91 else:
 92     # Try and load external backend.

 /anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in <module>
 52 
 53 # Private TF Keras utils
 ---> 54 get_graph = tf_keras_backend.get_graph
 55 # learning_phase_scope = tf_keras_backend.learning_phase_scope  # 
TODO
 56 name_scope = tf.name_scope

AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'

I googled the issue and found this

https://forums.xilinx.com/t5/Deephi-DNNDK/Module-tensorflow-python-keras-backend-has-no-attribute-get/td-p/1022555

which tells me that it is tensorflow version related, but not which version to use. I am using Python3 on MacOS.

Thank you for your help.

3
  • As per the release notes, 2.3 Keras is compatible with both TF1.x and TF2 releases. github.com/keras-team/keras/releases Sep 28, 2019 at 5:52
  • Please provide the stack trace of the error, so that it's easier to know why the problem is happening. Sep 28, 2019 at 5:53
  • @ManojMohan yeah, I agree that there shouldn't be an issue since I am using TF2 and it says they are compatible. I posted the stack trace in the post. Thanks!
    – ShieldData
    Sep 28, 2019 at 16:30

1 Answer 1

5

I couldn't reproduce the error you observe with Keras 2.3.0 & tensorflow 2.0.0rc1. Although, I was able to start the training of acgan, I got a different error after one iteration: Resource localhost/_AnonymousVar84/N10tensorflow3VarE does not exist.

I could successfully run the example with the following versions:

  1. Keras 2.2.4/tensorflow 1.14.0
  2. tensorflow 2.0.0rc1 and replace keras with tensorflow.keras in the imports.
1
  • I'm using tf - 1.10.0 and keras 2.3.0, the second point works for me, i.e. replacing keras with tensorflow.keras can you explain why?
    – Ishaan
    Jan 19, 2020 at 7:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.