美文网首页我爱编程
TensorFlow 学习 (一) TensorFlow安装

TensorFlow 学习 (一) TensorFlow安装

作者: Mr_差不多 | 来源:发表于2018-06-20 14:25 被阅读25次

    简介

    TensorFlow 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。TensorFlow 功能广泛,但是主要作为一种机器学习工具,用于构建深度神经网络模型。

    基本原理

    从TensorFlow的名字可以看出,Tensor表示张量可以理解为多维数组,Flow是流动可以理解为对张量的计算,那么TensorFlow可以看做是对若干张量进行若干计算的过程。该过程可以用数据流图来表示。


    20161213143212093.gif

    数据流图用“节点”(nodes)和“线”(edges)的有向图来描述数学计算。节点表示数据输入(feed in)的起点/输出(push out)的终点,“线”表示“节点”之间的输入/输出关系。节点数据通过一定的计算模型进行若干次训练得出最接近真实数据的值,就是TensorFlow的计算过程。

    安装TensorFlow

    Mac上安装TensorFlow有下面几种方法:

    • Virtualenv
    • “原生”pip
    • Docker
    • 从源代码安装
      建议采用 Virtualenv 安装方式。 Virtualenv 是一个与其他 Python 开发相互隔离的虚拟 Python 环境,它无法干扰同一计算机上的其他 Python 程序,也不会受其影响。在 Virtualenv 安装过程中,不仅将要安装 TensorFlow,还会安装 TensorFlow 需要的所有软件包。(这一过程其实很简单。)要开始使用 TensorFlow,只需要“激活”虚拟环境。总而言之,Virtualenv 提供一种安全可靠的机制来安装和运行 TensorFlow。

    使用 Virtualenv 进行安装

    1.启动终端
    2.安装pip和 Virtualenv

    $ sudo easy_install pip
    $ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade virtualenv 
    

    3.创建一个Virtualenv环境

    $ virtualenv --system-site-packages targetDirectory # for Python 2.7
    $ virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n
    

    4.激活该 Virtualenv 环境

    $ cd targetDirectory
    $ source ./bin/activate      # If using bash, sh, ksh, or zsh
    $ source ./bin/activate.csh  # If using csh or tcsh 
    

    5.安装TensorFlow(使用国内的 PyPI 镜像)

    (targetDirectory)$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow      # for Python 2.7
    (targetDirectory)$ pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow     # for Python 3.n
    

    然后在终端输入python进入python开发环境输入

    import tensorflow as tf
    print(tf.__version__)
    

    如果能看到打印出对应的版本信息就表示TensorFlow已经成功安装。

    相关文章

      网友评论

        本文标题:TensorFlow 学习 (一) TensorFlow安装

        本文链接:https://www.haomeiwen.com/subject/bywtyftx.html