目录
1、TF数据流图
1.1 TensorFlow结构分析
1.2 案例
2、图与TensorBoard
2.1 图结构
2.2 图相关操作
2.2.1 默认图
2.2.2 创建图
2.3 TensorBoard:可视化学习
2.3.1 数据序列化 - events文件
2.3.2 启动TensorBoard
2.4 OP
2.4.1 常见OP
2.4.2 指令名称
- TF数据流图
- 图与TensorBoard
- 会话
- 张量
- 变量OP
- 高级API
1、TF数据流图
1.1 TensorFlow结构分析
1.2 案例
import tensorflow as tfdef tensorflow_demo():# tensorflow基本结构# 原生python加法计算a = 3b = 4c = a +bprint("c:\n",c)# tensorflow实现加法计算a_t = tf.constant(2)b_t = tf.constant(3)c_t = a_t + b_tprint("tensorflow:\n",c_t)# 开启会话with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value:\n",c_t_value)return Noneif __name__ == "__main__":# 代码1 :tensorflow基本结构tensorflow_demo()
2、图与TensorBoard
2.1 图结构
2.2 图相关操作
2.2.1 默认图
import tensorflow as tfdef graph_demo():# 图的演示# Tensorflow实现加法运算a_t = tf.constant(2)b_t = tf.constant(3)c_t = a_t + b_tprint("tensorflow:\n", c_t)# 查看默认图# 方法1:调用方法default_g = tf.get_default_graph()print("default:\n",default_g)# 方法2:查看属性print("a_t的图属性:\n",a_t.graph)print("c_t的图属性:\n",c_t.graph)# 开启会话with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value:\n", c_t_value)print("sess的图属性:\n", sess.graph)return Noneif __name__ == "__main__":# 代码2:图的演示graph_demo()
2.2.2 创建图
import tensorflow as tfdef graph_demo():# 图的演示# Tensorflow实现加法运算a_t = tf.constant(2)b_t = tf.constant(3)c_t = a_t + b_tprint("tensorflow:\n", c_t)# 查看默认图# 方法1:调用方法default_g = tf.get_default_graph()print("default:\n",default_g)# 方法2:查看属性print("a_t的图属性:\n",a_t.graph)print("c_t的图属性:\n",c_t.graph)# 开启会话with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value:\n", c_t_value)print("sess的图属性:\n", sess.graph)# 自定义图new_g = tf.Graph()# 在自己的图中定义数据和操作with new_g.as_default():a_new = tf.constant(20)b_new = tf.constant(30)c_new = a_new + b_newprint("c_new:\n",c_new)return Noneif __name__ == "__main__":# 代码2:图的演示graph_demo()
import tensorflow as tfdef graph_demo():# 图的演示# Tensorflow实现加法运算a_t = tf.constant(2)b_t = tf.constant(3)c_t = a_t + b_tprint("tensorflow:\n", c_t)# 查看默认图# 方法1:调用方法default_g = tf.get_default_graph()print("default:\n",default_g)# 方法2:查看属性print("a_t的图属性:\n",a_t.graph)print("c_t的图属性:\n",c_t.graph)# 自定义图new_g = tf.Graph()# 在自己的图中定义数据和操作with new_g.as_default():a_new = tf.constant(20)b_new = tf.constant(30)c_new = a_new + b_newprint("c_new:\n",c_new)print("a_new的图属性:\n", a_new.graph)print("c_new的图属性:\n", c_new.graph)# 开启会话with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value:\n", c_t_value)print("sess的图属性:\n", sess.graph)# 开启new_g的会话with tf.Session(graph = new_g) as new_sess:c_new_value = new_sess.run((c_new))print("c_new_value:\n",c_new_value)print("new_sess的图属性:\n",new_sess.graph)return Noneif __name__ == "__main__":# 代码2:图的演示graph_demo()