文档说,当使用TensorFlow后端时,如果检测到Keras,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)
这里是which 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.
这是nvidia-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上运行。我该如何解决这个问题?
答案 0 :(得分:3)
您可能已安装了tensorflow的CPU版本。
因为您似乎正在使用Anaconda和py2.7: 按照these steps使用py2.7
在conda env中安装GPU版本的tensorflowconda 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 issue