美文网首页TensorFlow与NLP学习
TensorFlow Mac 本地环境搭建

TensorFlow Mac 本地环境搭建

作者: Joshua_精东 | 来源:发表于2019-03-12 23:45 被阅读0次

    昨天试了用Docker跑NLP的Demo,挺顺利,不过今天在学习TF的时候遇到点问题,依然需要一个本地环境来调试。

    Step 1 安装Anaconda3

    我本地早已经安装好了,在此不重复说了,需要的同学去官网下载安装。

    Step 2 使用Conda创建tensorflow环境

    conda create -n tensorflow pip python=3.6
    source activate tensorflow
    

    更新pip环境

    pip install --upgrade pip
    

    Step 3 安装TensorFlow包

    pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
    

    此处我翻墙了😜

    Step 4 测试下

    (tensorflow) Joshuas-iMac-Pro:~ joshua$ python
    Python 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46) 
    [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    >>> tf.__version__
    '1.12.0'
    >>> exit()
    

    Step 5 退出环境

    source deactivate
    

    Step 6 练习

    创建一个新环境

    source activate cnn-text-classification-tf
    

    自己也写了一段练习作业

    import tensorflow as tf
    
    
    def basic_operation():
        v1 = tf.Variable(10)
        v2 = tf.Variable(5)
        addv = v1 + v2
        print(addv)
        print(type(addv))
    
        c1 = tf.constant(10)
        c2 = tf.constant(5)
        addc = c1 + c2
    
        print(addc)
        print(type(addc))
        print(type(c1))
    
        sess = tf.Session()
        tf.global_variables_initializer().run(session=sess)
    
        print(addv.eval(session=sess))
        print(sess.run(addv))
    
        graph = tf.Graph()
        with graph.as_default():
            value1 = tf.constant([1, 2])
            value2 = tf.Variable([3, 4])
            mul = value1 * value2
    
        with tf.Session(graph=graph) as mySession:
            tf.global_variables_initializer().run()
            print('乘法(value1, value2) = ', mySession.run(mul))
            print('乘法(value1, value2) = ', mul.eval())
    
    
    if __name__ == '__main__':
        basic_operation()
    
    

    相关文章

      网友评论

        本文标题:TensorFlow Mac 本地环境搭建

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