我構建了docker圖像https://github.com/floydhub/dl-docker的gpu版本,keras版本2.0.0和tensorflow版本0.12.1。然後我運行了mnist教程https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py,但意識到keras沒有使用GPU。下面是我的輸出Keras與TensorFlow後端不使用GPU
[email protected]:~/sharedfolder# python test.py
Using TensorFlow backend.
Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
Train on 60000 samples, validate on 10000 samples
Epoch 1/12
2017-09-06 16:26:54.866833: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-06 16:26:54.866855: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-06 16:26:54.866863: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-09-06 16:26:54.866870: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-06 16:26:54.866876: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
任何人都可以讓我知道,如果有一些設置需要在keras使用GPU之前做出?我對這些都很陌生,所以如果我需要提供更多信息,請告訴我。
我已經安裝了先決條件的page
- 提到下面的安裝指南平臺安裝泊塢窗:https://docs.docker.com/engine/installation/
我能夠啓動泊塢窗圖像
docker run -it -p 8888:8888 -p 6006:6006 -v /sharedfolder:/root/sharedfolder floydhub/dl-docker:cpu bash
- 僅限GPU版本:直接在Nvidia上安裝Nvidia驅動程序或按照說明書here安裝。請注意,您不必安裝CUDA或cuDNN。這些包含在Docker容器中。
我能夠運行的最後一步
[email protected]:~$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 375.66 Mon May 1 15:29:16 PDT 2017
GCC version: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
- GPU版:安裝NVIDIA-泊塢窗:https://github.com/NVIDIA/nvidia-docker,這裏的操作說明。這將安裝Docker CLI的替代品。它負責在Docker容器內部設置Nvidia主機驅動程序環境以及其他一些內容。
我能夠運行步驟here
# Test nvidia-smi
[email protected]:~$ nvidia-docker run --rm nvidia/cuda nvidia-smi
Thu Sep 7 00:33:06 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.66 Driver Version: 375.66 |
|-------------------------------+----------------------+----------------------+
| 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 780M Off | 0000:01:00.0 N/A | N/A |
| N/A 55C P0 N/A/N/A | 310MiB/4036MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+
我也可以運行NVIDIA-泊塢窗命令來啓動一個GPU支持的圖像。
我已經試過
我曾嘗試下面
- 檢查下列建議,如果你已經完成了本教程(https://github.com/ignaciorlando/skinner/wiki/Keras-and-TensorFlow-installation)的第9步。注意:您的文件路徑在該Docker鏡像中可能完全不同,您必須以某種方式找到它們。
我將建議的行附加到我的bashrc並驗證了bashrc文件已更新。
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64' >> ~/.bashrc
echo 'export CUDA_HOME=/usr/local/cuda-8.0' >> ~/.bashrc
要在我的Python文件
import os os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152 os.environ["CUDA_VISIBLE_DEVICES"]="0"
兩個步驟,完成單獨或一起可惜沒能解決問題導入下面的命令。 Keras仍然使用tensorflow的CPU版本作爲其後端。但是,我可能已經找到了可能的問題。我通過以下命令檢查了我的tensorflow版本,發現其中兩個。
這是CPU版本
[email protected]:~# pip show tensorflow
Name: tensorflow
Version: 1.3.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: tensorflow-tensorboard, six, protobuf, mock, numpy, backports.weakref, wheel
而這是GPU版本
[email protected]:~# pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 0.12.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: mock, numpy, protobuf, wheel, six
有趣的是,輸出顯示keras使用tensorflow版本1.3.0這是CPU版本,而不是0.12.1中,GPU版本
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
import tensorflow as tf
print('Tensorflow: ', tf.__version__)
輸出
[email protected]:~/sharedfolder# python test.py
Using TensorFlow backend.
Tensorflow: 1.3.0
我想現在我需要弄清楚如何讓keras使用tensorflow的gpu版本。
如果你按照你的操作系統的Tensorflow安裝指南(https://www.tensorflow.org/install/)它會告訴你你需要的一切。您很可能會錯過CUDA和CUDAnn庫。 – KDecker
@KDecker,但它在https://github.com/floydhub/dl-docker上說,gpu版本附帶CUDA 8.0和cuDNN v5 – kong
哦,這是Docker鏡像。對不起,我瞥了一眼。我不確定要告訴你什麼,除此之外,你是否按照圖像補償? (安裝NVidia驅動程序和nvidia-docker) – KDecker