简体   繁体   English

在使用 tf.keras 时,我们是否需要分别检查 'tensorflow' 和 'keras',它们是否在 GPU 上运行?

[英]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 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 .在遵循从 Tensorflow 1.14 到 Tensorflow 2.0 的迁移指南之后,我从tensorflow.keras而不是仅仅从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但只需从keras导入后端即可

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'.我想知道keras是否使用GPU,我不明白'keras'和'tf.keras'的交互。 My entire neural network is built on layers imported from tensorflow.keras我的整个神经网络建立在从tensorflow.keras导入的层上

Edit: I am using a customised ImageDataGenerator function, this is how I am importing it -编辑:我正在使用自定义的 ImageDataGenerator 函数,这就是我导入它的方式 -

from keras.preprocessing.image import ImageDataGenerator从 keras.preprocessing.image 导入 ImageDataGenerator

instead of from tensorflow.keras.preprocessing.image import ImageDataGenerator .而不是from tensorflow.keras.preprocessing.image import ImageDataGenerator That's why I want to check if Keras is also running on GPU.这就是为什么我想检查 Keras 是否也在 GPU 上运行。 Do I need to ensure this?我需要确保这一点吗? If yes, how?如果是,如何?

From Keras repo :从 Keras 回购:

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. Keras 是一种高级神经网络 API,用 Python 编写,能够在 TensorFlow、CNTK 或 Theano 之上运行。在安装 Keras 之前,请安装其后端引擎之一:TensorFlow、Theano 或 CNTK。 (We recommend the TensorFlow backend). (我们推荐使用 TensorFlow 后端)。 So Keras is a skin (an API).所以 Keras 是一个皮肤(一个 API)。 TensorFlow has decided to include this skin inside itself as tf.keras. TensorFlow 已决定将此皮肤作为 tf.keras 包含在其自身中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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