Keras在使用TensorFlow后端时忽略GPU

Keras在使用TensorFlow后端时忽略GPU,tensorflow,keras,Tensorflow,Keras,文件说,当使用TensorFlow后端时,如果检测到Keras,它会自动在GPU上运行。我登录到一个远程GPU,并尝试运行Keras程序,但我只是出于某种原因使用CPU。如何强制我的Keras程序在GPU上运行以加快速度 如果有帮助,这就是模型的外观: model = Sequential() model.add(SimpleRNN(out_dim, input_shape = (X_train.shape[1], X_train.shape[2]), return_sequences = Fa

文件说,当使用TensorFlow后端时,如果检测到Keras,它会自动在GPU上运行。我登录到一个远程GPU,并尝试运行Keras程序,但我只是出于某种原因使用CPU。如何强制我的Keras程序在GPU上运行以加快速度

如果有帮助,这就是模型的外观:

model = Sequential()
model.add(SimpleRNN(out_dim, input_shape = (X_train.shape[1], X_train.shape[2]), return_sequences = False))
model.add(Dense(num_classes, activation='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer = "adam", metrics = ['accuracy'])
hist = model.fit(X_train, dummy_y, validation_data=(X_test, dummy_y_test), nb_epoch = epochs, batch_size = b_size)
下面是python的输出,并证明Keras正在使用TensorFlow后端:

user@GPU6:~$ which python
/mnt/data/user/pkgs/anaconda2/bin/python
user@GPU6:~$ python
Python 2.7.12 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import keras
Using TensorFlow backend.
这是英伟达smi的输出。我有几个类似上面的进程正在运行,但它们只使用CPU:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57                 Driver Version: 367.57                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX TIT...  Off  | 0000:03:00.0     Off |                  N/A |
| 26%   27C    P8    13W / 250W |      9MiB /  6082MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX TIT...  Off  | 0000:83:00.0     Off |                  N/A |
| 26%   31C    P8    13W / 250W |      9MiB /  6082MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  GeForce GTX TIT...  Off  | 0000:84:00.0     Off |                  N/A |
| 26%   31C    P8    14W / 250W |      9MiB /  6082MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      2408    G   Xorg                                             9MiB |
|    1      2408    G   Xorg                                             9MiB |
|    2      2408    G   Xorg                                             9MiB |
+-----------------------------------------------------------------------------+

我的所有进程都没有在GPU上运行。如何修复此问题?

您可能已经安装了tensorflow的CPU版本

由于您的计算机似乎正在使用Anaconda和py2.7: 接下来使用py2.7在conda env中安装tensorflow的GPU版本

conda create -n tensorflow
source activate tensorflow
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl
看到这个github了吗