1. 程式人生 > >tensorflow 環境搭建(centos與windows)

tensorflow 環境搭建(centos與windows)

1. windows下安裝


2. centos下安裝

按順序一步一步解決依賴並安裝。

1.1 python

筆者使用的版本為2.7.5 .

2.1 python-pip

pip,Python Index Package。類似linux下的yum,安裝並管理python軟體包。
pip安裝命令:yum install  python-pip python-devel
備註:不安裝python-devel的話,pynum安裝就會報錯。這是一個py下的數學計算擴充套件包。

3.1 tensorflow

終於開始安裝它本身了。

tensorflow 安裝命令:pip install  https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl

安裝之後的升級命令:pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.6.0-cp27-none-linux_x86_64.whl

安裝過程需要持續近10分鐘,因為有大量的編譯工作。

3.測試安裝成功與否

#tensorflowTest.py
import tensorflow as tf
hello = tf.constant('Hello,TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
執行 python tensorflowTest.py ,若最終結果與下面兩行一致,則恭喜你安裝成功!附執行結果的截圖,見圖4-1.
//TensorFlow.py 執行結果
Hello, TensorFlow!
42

圖3-1 linux下tensflow執行成功, windows也一樣

4. 常見問題

執行的時候會有下面的警告資訊輸出, 但程式仍能執行.大致原因是pip安裝的是預編譯 tensorflow 庫, 沒有針對當前的cpu體系進行優化.
2017-05-05 11:18:58.162500: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-05-05 11:18:58.162995: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-05-05 11:18:58.163347: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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.
2017-05-05 11:18:58.164001: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-05-05 11:18:58.164352: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-05-05 11:18:58.164699: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-05-05 11:18:58.165029: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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-05-05 11:18:58.165292: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\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.