目录
Tensorflow框架
Tensorflow的特点
Tensorflow基础
Tensorflow的编程习惯
import tensorflow as tf
# 实现一个加法运算
a=tf.constant(3.0)
b=tf.constant(4.0)
sum=tf.add(a,b)
with tf.Session() as sess:
print(sess.run(sum))
Tensorflow的设计基本思想
tensor:每个数据可以用张量表示,图中的有向线段表示为张量;
operation(op):专门运算的操作节点,所有的操作都是一个op;
graph:图,你的整个程序的结构;
Session:会话,运行程序的图。
Tensorflow进阶
图
import tensorflow as tf
# 实现一个加法运算
a=tf.constant(3.0)
b=tf.constant(4.0)
sum=tf.add(a,b)
# 默认的这张图,相当于是给程序分配一段内存
graph = tf.get_default_graph()
print(graph)
with tf.Session() as sess:
print(sess.run(sum))
print(a.graph)
print(sum.graph)
print(sess.graph)
<tensorflow.python.framework.ops.Graph object at 0x000002A5D4BF10F0>
7.0
<tensorflow.python.framework.ops.Graph object at 0x000002A5D4BF10F0>
<tensorflow.python.framework.ops.Graph object at 0x000002A5D4BF10F0>
<tensorflow.python.framework.ops.Graph object at 0x000002A5D4BF10F0>
创一个新的图——tf.Graph()
import tensorflow