首頁 > 軟體

Ubuntu 18.04安裝Tensorflow(CPU)

2020-06-16 16:35:36

最近我開始學習深度學習框架Tensorflow,一開始在Windows平台下的anaconda下安裝,由於anaconda安裝幾次後navigator開啟老是出現閃退的問題,所以決定換個Ubuntu下繼續折騰tensorflow。本人筆電沒有NVIDIA顯示卡,只裝的CPU版本的。而且是在虛擬機器下的,下面開始吧。

先安裝好Ubuntu 18.04版本的系統(最好是Ubuntu的14.04版本以上),Ubuntu系統已經有了了Python 3.7.7.7,所以不需要再安裝Python了。

一、首先更新源為阿里雲軟體源,增加下載速度

(1)備份當前也就是預設官方的源列表

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

(2)刪除sources.list檔案中的列表,刪除全部內容

sudo gedit /etc/apt/sources.list1

(3)替換內容後,儲存

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

4)更新源列表

sudo apt-get update

二、安裝Tensorflow(Python3.6.7/CPU)

(1)安裝Python3的包管理pip

sudo apt-get install python3-pip python3-dev

(2)安裝tensorflow

(自動安裝相關庫numpy、tensorboard、six、protobuf、html5lib、bleach、werkzeug、markdown)

linuxidc@linuxidc:~/linuxidc.com$ sudo pip3 install tensorflow

(3)測試tensorflow

linuxidc@linuxidc:~/linuxidc.com$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> a = tf.constant(1)
>>> b = tf.constant(2)
>>> op = a + b
>>> sess = tf.Session()
2019-06-02 06:35:29.407386: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-06-02 06:35:29.427402: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1799995000 Hz
2019-06-02 06:35:29.427627: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x24f1710 executing computations on platform Host. Devices:
2019-06-02 06:35:29.427675: I tensorflow/compiler/xla/service/service.cc:158]  StreamExecutor device (0): <undefined>, <undefined>
>>> sess.run(op)
3
>>> sess.close()
>>>


IT145.com E-mail:sddin#qq.com