我是靠谱客的博主 高挑雪糕,这篇文章主要介绍【tflearn系列教程】(二)如何安装tflearn,现在分享给大家,希望可以做个参考。

本教程参考自tflearn官方文档(英文版)http://tflearn.org,主要是对官方文档的翻译与讲解,并结合本人实战经验而作,如有错误,欢迎指出!
作者 : totorocyx    邮箱 : 847994259@qq.com(转载请联系)

一、从tensorflow开始的旅程

安装TFLearn 需要先安装 Tensorflow (version 1.0+) 。如果已经装好的可以跳过这一节。( 注意:此安装教程是基于ubuntu系统的,其他系统暂时不给出具体教程,请自行研究,大同小异。)安装tensorflow有多种方法,笔者推荐使用anaconda安装,并且使用anaconda创建一个tensorflow专属环境,在环境中安装,便于管理。可以参考这位博主的教程 来安装anaconda。假设读者已经安装好anaconda:

  • STEP 1:创建tensorflow专属环境并激活环境:
复制代码
1
2
3
4
5
6
7
# 创建环境 基于python3.5 $ conda create -n tensorflow python=3.5 # 激活环境 $ source activate tensorflow #附 退出当前环境的命令 $ source deactivate tensorflow
  • STEP 2:根据自己的系统选择正确的版本。笔者用的系统是ubuntu16.04 LTS,64位,集显(无GPU),python3.5,故选择的是 ubuntu/Linux 64-bit, CPU only, Python 3.5 。选择好后,Ctrl+Alt+T 打开终端,拷贝对应的命令:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Ubuntu/Linux 64-bit, CPU only, Python 2.7 $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whl # Ubuntu/Linux 64-bit, GPU enabled, Python 2.7 # Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below. $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-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-1.1.0-py2-none-any.whl # Mac OS X, GPU enabled, Python 2.7: $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.1.0-py2-none-any.whl # Ubuntu/Linux 64-bit, CPU only, Python 3.3 $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp33-cp33m-linux_x86_64.whl # Ubuntu/Linux 64-bit, GPU enabled, Python 3.3 # Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below. $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp33-cp33m-linux_x86_64.whl # Ubuntu/Linux 64-bit, CPU only, Python 3.4 $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp34-cp34m-linux_x86_64.whl # Ubuntu/Linux 64-bit, GPU enabled, Python 3.4 # Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below. $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-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-1.1.0-cp35-cp35m-linux_x86_64.whl # Ubuntu/Linux 64-bit, GPU enabled, Python 3.5 # Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below. $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl # Ubuntu/Linux 64-bit, CPU only, Python 3.6 $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp36-cp36m-linux_x86_64.whl # Ubuntu/Linux 64-bit, GPU enabled, Python 3.6 # Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below. $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp36-cp36m-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-1.1.0-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_gpu-1.1.0-py3-none-any.whl
  • STEP 3:使用以下命令安装:
复制代码
1
2
3
4
5
# Python 2 $ pip install --ignore-installed --upgrade $TF_BINARY_URL # Python 3 $ pip3 install --ignore-installed --upgrade $TF_BINARY_URL

注意:

  • 如果在python3的anaconda环境中安装,那么pip和pip3没有区别。

  • 若在anaconda环境中安装,并且只想装在当前环境下(假设环境名为tensorflow),那么不要加sudo,因为sudo安装是使用的默认python(可以理解为全局python),会对所有环境都有效。

  • 若想在ipython下使用tensorflow包,那么必须先在此环境下安装ipython,再使用ipython(基于python2的环境)或ipython3(基于python3的环境)命令调出当前环境下的ipython,才能正确import安装好的tensorflow包,否则可能出现语法错误的提示。原因:直接使用ipython可能调出的是系统默认环境下的ipython,与当前环境下的python版本不匹配。在当前环境下配置的tensorflow是和当前环境下的python版本紧密结合的,所以ipython的python版本必须和当前环境下的python版本完全一致。可以使用下列方法来检查调出的ipython是不是当前环境下的ipython:

    复制代码
    1
    2
    import sys sys.path

    查看显示出来的路径是否有 ~/anaconda3/envs/tensorflow/… 即tensorflow环境所在路径。如果有,那么就没有问题。


  • STEP 4:测试环境
    进入python或ipython环境,输入import tensorflow as tf 看是否可以成功导入包。若没有出现错误提示,那么安装成功。可以试着运行以下一小段demo程序:

复制代码
1
2
3
4
5
6
7
8
# 计算两个矩阵的乘法 import tensorflow as tf matrix1=tf.constant([[3.,3.]]) matrix2=tf.constant([[2.],[2.]]) product=tf.matmul(matrix1,matrix2) sess=tf.Session() res=sess.run(product) print(res)

二、安装tflearn

在安装tflearn之前,除了要确保tensorflow成功安装外,还要安装额外的两个依赖包,否则运行时会发生错误(即使可以成功安装):

复制代码
1
pip install scipy h5py

之后使用以下语句进行安装(根据个人喜好自己选择安装方式,二选一):

复制代码
1
2
3
4
5
6
7
# 安装最新beta版 $ pip install git+https://github.com/tflearn/tflearn.git (需先安装git,如果没有安装,使用sudo apt-get install git命令进行安装) # 安装最近的稳定版 $ pip install tflearn

最后进入python环境,import tflearn 若成功导入,则安装成功。如果出错,多数是因为之前的tensorflow配置错误,抑或是python版本出错,请参阅上边的教程,确保正确安装。


By totorocyx

最后

以上就是高挑雪糕最近收集整理的关于【tflearn系列教程】(二)如何安装tflearn的全部内容,更多相关【tflearn系列教程】(二)如何安装tflearn内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(83)

评论列表共有 0 条评论

立即
投稿
返回
顶部