深度學習框架TensorFlow學習(一)------關於Tensorflow的簡介和配置

1. 簡介

百度百科:TensorFlow是谷歌基於DistBelief進行研發的第二代人工智能學習系統,其命名來源於本身的運行原理。Tensor(張量)意味着N維數組,Flow(流)意味着基於數據流圖的計算,TensorFlow爲張量從圖象的一端流動到另一端計算過程。TensorFlow是將複雜的數據結構傳輸至人工智能神經網中進行分析和處理過程的系統。
TensorFlow可被用於語音識別或圖像識別等多項機器深度學習領域,對2011年開發的深度學習基礎架構DistBelief進行了各方面的改進,它可在小到一部智能手機、大到數千臺數據中心服務器的各種設備上運行。TensorFlow將完全開源,任何人都可以用。

維基百科:TensorFlow is an open source software library for machine learning in various kinds of perceptual and language understanding tasks. It is currently used for both research and production by different teams in dozens of commercial Google products, such as speech recognition, Gmail, Google Photos, and search, many of which had previously used its predecessor DistBelief. TensorFlow was originally developed by the Google Brain team for Google’s research and production purposes and later released under the Apache 2.0 open source license on November 9, 2015。(大概意思就是Tensorflow應用廣泛,工業和學術界都在使用,由Google Brain team 研發的,然後給開源出來了。)

從這兩個大概的簡介中可以看出來,Tensorflow的應用還是十分廣泛的,不論是在學術界還是工業界,而且,近幾年來視覺頂會的文章也都陸續的放出Tensorflow版本的code。而且,大多數的公司給出的招聘啓事中明確表示,熟悉Tensorflow的優先等等問題,都表明了Tensorflow逐漸在深度學習界表現出來的強大的性能(誰讓有個好爹呢~~~~)和受歡迎度。所以,簡單瞭解學習一下這個深度框架也是不錯的。

2、環境搭建

我的環境是Ubuntu Kylin 14.04 + Python 2.7(還是習慣使用2.7的python)
下面就是安裝步驟了:
第一種方法:
①首先你要有一個linux的系統或者Mac系統,因爲到目前爲止,Tensorflow還是只能在這兩個系統上進行配置的,希望以後會有Windows版本吧。
②下載Tensorflow地址,看好對應的版本,有python2和python3,有GPU或者沒有GPU的版本等。
③開始安裝,使用python pip tensorflow-0.11.0rc0-*.whl安裝完成即可。

第二種方法:
①同樣你得需要有系統。
②這個相對比較簡單,而且不會出錯誤的。
(1)先安裝pip

# Ubuntu/Linux 64-bit
$ sudo apt-get install python-pip python-dev

# Mac OS X
$ sudo easy_install pip
$ sudo easy_install --upgrade six

如果Ubuntu使用這個方式安裝pip出錯的話,建議去這裏下載安裝pip,然後繼續進行下一步
(2)使用pip安裝TensorFlow,各個版本對應的代碼我給放出來(其實就是官網拷貝過來的,哈哈~~~)

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

# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc0-cp27-none-linux_x86_64.whl

# Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc0-py2-none-any.whl

# Mac OS X, GPU enabled, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0rc0-py2-none-any.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.4
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc0-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc0-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.5
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc0-cp35-cp35m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5
# Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc0-cp35-cp35m-linux_x86_64.whl

# Mac OS X, CPU only, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc0-py3-none-any.whl

# Mac OS X, GPU enabled, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.11.0rc0-py3-none-any.whl

好了,如果到這個時候沒有出現什麼錯誤,而且完成的話,那麼表示你已經成功安裝了Tensorflow框架了。

3、測試

下面我們就進行測試一下,我們的框架是夠安裝完好,並且能夠正常運行呢~~~
我們打開一個終端,輸入python,切換到python IDE,輸入以下代碼:

$ 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
>>>

如果你的也是正常輸出Hello,TensorFlow!和42說明已經正確安裝好了Tensorflow框架。接下來我們就可以繼續去學習者框架了。~~~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章