美文网首页我爱编程
入门 tensorflow(一)

入门 tensorflow(一)

作者: Kean_L_C | 来源:发表于2017-08-03 10:50 被阅读32次

    tensorflow-gpu的几个坑

    1. 940mx显卡:cuda8+cudnn5
    2. 1050:cuda8安装选自定义安装,仅仅选择cuda即可,cudnn6
    3. 配置cudnn路径变量
    4. vs2017不支持,仅仅支持2013,2015
    5. 安装tensorflow之前需要配置:C:\Windows\System32\msvcp140.dll环境变量
    6. 参考1 参考2
    7. vs2015地址

    你的第一个Grpah & run it in a session

    在开始之前不妨先了解下特你tensorflow的一些基本概念:中文社区,当然如果你已经了解,跳过。

    A TensorFlow program is typically split into two parts:

    • the first part builds a computation graph (this is called the construction phase)

    • the second part runs it (this is the execution phase). The construction phase typically builds a computation graph representing the ML model and the computations required to train it. The execution phase generally runs a loop that evaluates a training step repeatedly (for example, one step per mini-batch), gradually improving the model parameters.

    # encoding: utf-8
    
    """
    @version: python3.5.2 
    @author: kaenlee  @contact: lichaolfm@163.com
    @software: PyCharm Community Edition
    @time: 2017/8/3 10:01
    purpose:
    """
    
    import tensorflow as tf
    
    # creates a computation graph
    x = tf.Variable(3, name="x")
    y = tf.Variable(4, name='y')
    f = tf.add(tf.multiply(tf.multiply(x, x), y), tf.add(y, 2)) #多个op组合成一个op
    
    #The following code creates a session, initializes the variables,
    sess = tf.Session()
    initial = tf.global_variables_initializer()
    sess.run(initial)
    
    #evaluates, and f then closes the session
    result = sess.run(f)
    print(result)
    sess.close()
    
    # 另外一种写法
    with tf.Session() as sess:
        x.initializer.run()
        y.initializer.run()
        res = sess.run(f)
        print(res)
    sess.close()
    

    相关文章

      网友评论

        本文标题:入门 tensorflow(一)

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