日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

ubuntu 16.04 安装TensorFlow GPU版本

發布時間:2024/2/28 Ubuntu 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu 16.04 安装TensorFlow GPU版本 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

推薦新版安裝教程

http://blog.csdn.net/chenhaifeng2016/article/details/78874883



在ubuntu 16.04上安裝cuda8.0和cudnn ?5.1,請參考以下內容?

http://blog.csdn.net/chenhaifeng2016/article/details/68957732



安裝TensorFlow

sudo apt-get install libcupti-dev


sudo apt-get install python-pip python-dev python-virtualenv

virtualenv --system-site-packages ~/tensorflow

source ~/tensorflow/bin/activate

pip install --upgrade tensorflow-gpu



測試TensorFlow

通過Pycharm創建測試工程


from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tfglobal mnist#遠程下載MNIST數據,建議先下載好并保存在MNIST_data目錄下 def DownloadData():global mnistmnist = input_data.read_data_sets("MNIST_data/", one_hot=True) #編碼格式:one-hot print(mnist.train.images.shape, mnist.train.labels.shape)print(mnist.test.images.shape, mnist.test.labels.shape)print(mnist.validation.images.shape, mnist.validation.labels.shape)def Train():sess = tf.InteractiveSession()#Step 1 #定義算法公式Softmax Regression x = tf.placeholder(tf.float32, [None, 784]) #構建占位符,代表輸入的圖像,None表示樣本的數量可以是任意的 W = tf.Variable(tf.zeros([784,10])) #構建一個變量,代表訓練目標weights,初始化為0 b = tf.Variable(tf.zeros([10])) #構建一個變量,代表訓練目標biases,初始化為0 y = tf.nn.softmax(tf.matmul(x, W) + b) #構建了一個softmax的模型:y = softmax(Wx + b)y指樣本標簽的預測值 #Step 2 #定義損失函數,選定優化器,并指定優化器優化損失函數 y_ = tf.placeholder(tf.float32, [None, 10]) # 構建占位符,代表樣本標簽的真實值 # 交叉熵損失函數 cross_entropy = -tf.reduce_sum(y_ * tf.log(y))#y = tf.matmul(x, W) + b #cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y)) # 使用梯度下降法(0.01的學習率)來最小化這個交叉熵損失函數 train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)#Step 3 #使用隨機梯度下降訓練數據 tf.global_variables_initializer().run()for i in range(1000): #迭代次數為1000 batch_xs, batch_ys = mnist.train.next_batch(100) #使用minibatch的訓練數據,一個batch的大小為100 sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) #用訓練數據替代占位符來執行訓練 #Step 4 #在測試集上對準確率進行評測 correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) #tf.argmax()返回的是某一維度上其數據最大所在的索引值,在這里即代表預測值和真值 accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) #用平均值來統計測試準確率 print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) #打印測試信息 sess.close()if __name__ == '__main__':DownloadData();Train();

運行效果

/home/chenhf/tensorflow/bin/python /home/chenhf/PycharmProjects/TensowflowTest/MnistDemo.py
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:126] Couldn't open CUDA library libcudnn.so.5. LD_LIBRARY_PATH: /home/chenhf/pycharm-2017.1/bin:/usr/local/cuda-8.0/lib64:
I tensorflow/stream_executor/cuda/cuda_dnn.cc:3517] Unable to load cuDNN DSO
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz
((55000, 784), (55000, 10))
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
((10000, 784), (10000, 10))
((5000, 784), (5000, 10))
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.
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.
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.
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.
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.
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:910] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:?
name: GeForce GTX 765M
major: 3 minor: 0 memoryClockRate (GHz) 0.8625
pciBusID 0000:01:00.0
Total memory: 1.95GiB
Free memory: 1.93GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0?
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: ? Y?
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 765M, pci bus id: 0000:01:00.0)
0.9162


Process finished with exit code 0

準確率在91.6%




--結束--

總結

以上是生活随笔為你收集整理的ubuntu 16.04 安装TensorFlow GPU版本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。