搜尋此網誌

2017年2月7日 星期二

tensorflow 安裝


安裝參考 Source

根據原文,日後如果新安裝高速顯卡,就要重新安裝 GPU 版

先安裝好 Python 2.7 環境

這次是在Ubuntu VM底下,並事先已經安裝好 Google Bazel
開始安裝 python 環境,sudo 指令最好是加 -H 參數:

sudo -H apt-get -y install python-pip python-dev
sudo -H pip install numpy
sudo -H pip install six
sudo -H pip install tensorflow


CPU 版
sudo -H pip install tensorflow

GPU 版則
sudo -H pip install tensorflow-gpu

# Ubuntu/Linux 64-bit, CPU only, Python 2.7 環境
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0rc1-cp27-none-linux_x86_64.whl



# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7 環境
# 且還必須先安裝好 Requires CUDA toolkit 8.0 and CuDNN v5. 
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0rc1-cp27-none-linux_x86_64.whl


# Python 2 版
sudo -H pip install --upgrade $TF_BINARY_URL


測試是否安裝成功
python

出現 >>> 提示下:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

會顯示 Hello, TensorFlow!

出現 >>> 提示下:
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
42

看到以上就是成功,不然 import tensorflow as tf 時候就已經報錯了。
輸入 exit() 離開


測試第一個 TensorFlow 類神經網路模型範例 neural net model

在 /home/user 目錄下,複製 models 倉庫一份
git clone https://github.com/tensorflow/models.git

完成後
cd ~/models/tutorials/image/mnist
執行
python convolutional.py

畫面看到以下輸出例子
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Initialized!
Epoch 0.00
Minibatch loss: 12.054, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Epoch 0.12
Minibatch loss: 3.285, learning rate: 0.010000
Minibatch error: 6.2%
Validation error: 7.0%
...

...


- The End -



沒有留言:

張貼留言

搜尋此網誌