- Deep Learning Quick Reference
- Mike Bernico
- 474字
- 2021-06-24 18:40:07
Installing TensorFlow and Keras
After everything we've just been through together, you'll be pleased to see how straightforward installing TensorFlow and Keras now is.
Let's start with installing TensorFlow
The installation of TensorFlow can be done using the following code:
pip install --upgrade tensorflow-gpu
Before we install Keras, let's test our TensorFlow installation. To do this, I'll be using some sample code from the TensorfFow website and the IPython interpreter.
Start the IPython interpreter by typing IPython at the bash prompt. Once IPython has started, let's attempt to import TensorFlow. The output would look like the following:
In [1]: import tensorflow as tf
In [2]:
If importing TensorFlow results in an error, troubleshoot the steps you have followed so far. Most often when TensorFlow cannot be imported, the CUDA or cuDNN might not be installed correctly.
Now that we've successfully installed TensorFlow, we will run a tiny bit of code in IPython that will verify we can run computations on the GPU:
a = tf.constant([1.0,</span> 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
If everything goes as we hope, we will see lots of indications that our GPU is being used. I have included some output here and highlighted the evidence to draw your attention to it. Your output will likely be different based on hardware, but you should see similar evidence the one shown here:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0
: I tensorflow/core/common_runtime/placer.cc:874] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
: I tensorflow/core/common_runtime/placer.cc:874] b: (Const)/job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
: I tensorflow/core/common_runtime/placer.cc:874] a: (Const)/job:localhost/replica:0/task:0/device:GPU:0
[[ 22. 28.]
[ 49. 64.]]
In the preceding output, we can see that tensors a and b, as well as the matrix multiplication operation, were assigned the the GPU. If there was a problem with accessing the GPU, the output might look as follows:
I tensorflow/core/common_runtime/placer.cc:874] b_1: (Const)/job:localhost/replica:0/task:0/device:CPU:0
a_1: (Const): /job:localhost/replica:0/task:0/device:CPU:0
I tensorflow/core/common_runtime/placer.cc:874] a_1: (Const)/job:localhost/replica:0/task:0/device:CPU:0
Here we can see the tensors b_1 and a_1 were assigned to the CPU rather than the GPU. If this happens there is a problem with your installation of TensorFlow, CUDA, or cuDNN.
If you've made it this far, you have a working installation of TensorFlow. The only remaining task is to install Keras.
The installation of Keras can be done with the help of the following code:
pip install keras
And that's it! Now we're ready to build deep neural networks in Keras and TensorFlow.
- 并行數(shù)據(jù)挖掘及性能優(yōu)化:關(guān)聯(lián)規(guī)則與數(shù)據(jù)相關(guān)性分析
- 2018西門子工業(yè)專家會議論文集(上)
- 自動檢測與轉(zhuǎn)換技術(shù)
- 傳感器技術(shù)應(yīng)用
- WordPress Theme Development Beginner's Guide(Third Edition)
- C語言寶典
- 高維聚類知識發(fā)現(xiàn)關(guān)鍵技術(shù)研究及應(yīng)用
- Splunk Operational Intelligence Cookbook
- 基于32位ColdFire構(gòu)建嵌入式系統(tǒng)
- ESP8266 Home Automation Projects
- Android游戲開發(fā)案例與關(guān)鍵技術(shù)
- Nginx高性能Web服務(wù)器詳解
- 網(wǎng)絡(luò)安全管理實踐
- MCGS嵌入版組態(tài)軟件應(yīng)用教程
- 工業(yè)機器人實操進階手冊