入门 tensorflow(一)

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()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容