简体   繁体   中英

While using tf.keras, do we need to separately check for both 'tensorflow' and 'keras', whether they are running on GPU?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM