3
文档说,当使用TensorFlow后端时,如果检测到Keras,它会自动在GPU上运行。我登录到远程GPU,并尝试运行Keras程序,但由于某种原因我只使用CPU。我如何强制Keras程序在GPU上运行以加快速度?Keras在使用TensorFlow后端时忽略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后端:
[email protected]:~$ which python
/mnt/data/user/pkgs/anaconda2/bin/python
[email protected]:~$ 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上运行。我怎样才能解决这个问题?