搭建深度学习基本环境(Ubuntu系统下)

搭建深度学习基本环境(Ubuntu系统下)

本人第一次写博客啦~


在ubuntu系统上安装Anaconda3

  • 下载linux安装包:
    1、从官网下载(如果电脑是64位,记得下载64-bit)
    2、命令行(注意网站的更新):
wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
  • 安装:
bash Anaconda3-5.2.0-Linux-x86_64.sh

如果是采用官网下载的话,则需要先进入“下载”目录中:

cd Downloads

后面的操作就是一直是yes或者是”enter”等傻瓜式操作啦~

  • 检测安装是否成功:
    直接在terminal输入:
python

还可以用“conda list”查看可用的packages。如果在这一步的python没有更新的话,那说明.bashrc的更新还没有生效,命令行输入:

source ./bashrc

在ubuntu系统上安装Tensorflow

建议这块的安装参考官网 [ tensorflow install ]

注意:由于实验室的服务器已经安装好了CUDA和cuDNN,因此我只需要安装Anaconda3和Tensorflow即可,如果服务器或者Ubuntu中没有CUDA和cuDNN的话,还需要先安装好CUDA和cuDNN再安装Tensorflow。

  • CPU:
    首先确认下自己的python 版本和pip:
python3 -V
pip3 -V

通常ubuntu系统都会自动安装pip或者是python,也可以自己安装一下:

sudo apt-get install python3-pip python3-dev # for Python 3.n

然后按照官网指示安装即可:

sudo pip3 install -U tensorflow  # Python 3.n

检验安装是否成功:

python -c "import tensorflow as tf; print(tf.__version__)"
  • GPU:
    1、首先我是按照官网上提到的“Use pip in Anaconda”方法尽心安装的:
$ conda create -n tensorflow pip python=3.6.5(注意这里一定要明确版本)
$ source activate tensorflow
(tensorflow)$ pip install --ignore-installed --upgrade tfBinaryURL

这里tfBinaryURL即是 URL of the TensorFlow Python package.

例如,我输入的命令位(对应3.6.5版本):

(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.10.1-cp36-cp36m-linux_x86_64.whl

检测是否安装成功:

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

如果出现啦”Hello,TensorFlow”的话,那么就是安装成功啦~
2、然而,很可惜我运行的时候出现了”libcublas.So.9.0~~”这样的错误,一查结果发现这是因为我安装的tensorflow1.10.0版本对应的是CUDA 9.0版本,而服务器上安装的是CUDA8.0,版本不匹配。后来,为了稳妥起见,首先将python3.6.5改为python3.5.6版本:

conda install python3.5

然后还是按照官网上的方法先创建一下tensorflow环境,然后安装tensorflow1.3.0版本:

(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-1.3.0-cp36-cp36m-linux_x86_64.whl

结果发现会提示“~is not supported ~ in the platform”等这样的错误,发现这是因为官网的URL of tensorflow已经更新至1.10.0版本啦。
如何安装older tensorflow呢?我后来在 [ stackoverflow~Install older version tensorflow ]上找到了答案,也就是直接在终端输入:

pip install tensorflow==1.3.0

检测是否安装成功:
import tensorflow as tf
hello = tf.constant(‘Hello, TensorFlow!’)
sess = tf.Session()
print(sess.run(hello))

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

结果在第三句代码后出现了很多warning:

2017-12-25 20:11:49.485908: W c:\l\work\tensorflow-1.1.0\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-12-25 20:11:49.486234: W c:\l\work\tensorflow-1.1.0\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.

这些warning出现主要是因为machine memory不够大,程序运行速度会比较慢等原因,但不会影响到程序运行。不想这些warning出现,则可以在命令前加入:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf

结果最终输出的是:

b'Hello Tensorflow!'

前面出现一个’b’的原因是“Python 3.x makes a clear distinction between the types”:

str = '...' literals = a sequence of Unicode characters (UTF-16 or UTF-32, depending on how Python was compiled)
bytes = b'...' literals = a sequence of octets (integers between 0 and 255)

如果不想出现’b’,则将最后一句命令改为:

print(sess.run(hello).decode())

这样就会出现完美的:

'Hello Tensorflow!'

祝各位搭建环境顺利啊~

猜你喜欢

转载自blog.csdn.net/jiudiyou5845/article/details/82468530