深度学习-TensorFlow实例
2018-07-20 本文已影响47人
老生住长亭
- 安装tensorflow1.9前,安装python3.6,安装环境为ubuntu18,
2.下载tensorflow 的whl文件,安装pip,
链接:https://pan.baidu.com/s/1DdAziXr-Sx4f9mwWgGRo0w 密码:lz3g
然后执行:pip3 install whl文件
- tensorflow不能跳过的hello word
import tensorflow as tf
print(tf.__version__)
结果:1.9.0
4.tensorflow 第一DAG使用(有向无环图),和spark的DAG是一回事
import tensorflow as tf
# with code run at cpu 0
with tf.device("/cpu:0"):
x = tf.Variable(3, name="x")
y = tf.Variable(4, name="y")
f = x * y + 3
# init session
session = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# start init x and y , function programer
session.run(x.initializer)
session.run(y.initializer)
# run f function
result = session.run(f)
print(result)
# session close
session.close()
结果:包括执行过程
x: (VariableV2): /job:localhost/replica:0/task:0/device:CPU:0
x/Assign: (Assign): /job:localhost/replica:0/task:0/device:CPU:0
x/read: (Identity): /job:localhost/replica:0/task:0/device:CPU:0
y: (VariableV2): /job:localhost/replica:0/task:0/device:CPU:0
y/Assign: (Assign): /job:localhost/replica:0/task:0/device:CPU:0
y/read: (Identity): /job:localhost/replica:0/task:0/device:CPU:0
mul: (Mul): /job:localhost/replica:0/task:0/device:CPU:0
add: (Add): /job:localhost/replica:0/task:0/device:CPU:0
x/initial_value: (Const): /job:localhost/replica:0/task:0/device:CPU:0
y/initial_value: (Const): /job:localhost/replica:0/task:0/device:CPU:0
add/y: (Const): /job:localhost/replica:0/task:0/device:CPU:0
15
tensorflow 比你想象第一个例子要简单。