0

I am using

Tensorflow 2.0

After following the migration guide from Tensorflow 1.14 to Tensorflow 2.0, I was importing all the modules from tensorflow.keras instead of just keras. But the following commands gives the Attribute error -

from tensorflow.keras import backend as K
K.tensorflow_backend._get_available_gpus()
Output: AttributeError: module 'tensorflow_core.keras.backend' has no attribute 'tensorflow_backend'

But just importing the backend from keras works

from keras import backend as K
K.tensorflow_backend._get_available_gpus()
Output:['/job:localhost/replica:0/task:0/device:GPU:0']

I want to know if keras is using GPU, and I don't understand the interaction of 'keras' and 'tf.keras'. My entire neural network is built on layers imported from tensorflow.keras

Edit: I am using a customised ImageDataGenerator function, this is how I am importing it -

from keras.preprocessing.image import ImageDataGenerator

instead of from tensorflow.keras.preprocessing.image import ImageDataGenerator. That's why I want to check if Keras is also running on GPU. Do I need to ensure this? If yes, how?

Malgo
  • 1,871
  • 1
  • 17
  • 30
  • Does this answer your question? [What is the difference between tf.keras and tf.python.keras?](https://stackoverflow.com/questions/58279628/what-is-the-difference-between-tf-keras-and-tf-python-keras) – Nicolas Gervais Dec 18 '19 at 04:54
  • It answers the seconda half of the questions. The first half to know whether my tf.keras model is using GPU or not is still unanswered... – Malgo Dec 18 '19 at 06:57
  • From - https://www.tensorflow.org/guide/gpu - here I understand that you can check if the tf code is running on GPU using - tf.config.experimental.list_physical_devices('GPU'). But my question is, is it necessary to check if tf.keras is also using GPU? If yes, then how? – Malgo Dec 18 '19 at 07:02

1 Answers1

0

From Keras repo :

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK. (We recommend the TensorFlow backend). So Keras is a skin (an API). TensorFlow has decided to include this skin inside itself as tf.keras.