人工智能的黑盒:
TensorBoard 的作用:
1.用TensorFlow保存图的信息到日志中
tfsummary.FileWriter("日志保存路径", sess.graph)
2.用TensorBoard 读取并展示日志
tensorboard --logdir=日志所在路径
summary(总结、概览)
- 用于导出关于模型的精简信息的方法
- 可以使用TensorBoard等工具访问这些信息
name_scope(命名空间)
- 很像一些编程语言(如C++)的namespace,包含/嵌套的关系
完整示例:
# -*- coding: UTF-8 -*-
# 引入tensorflow
import tensorflow as tf
# 构造图(Graph)的结构
# 用一个线性方程的例子 y = W * x + b
W = tf.Variable(2.0, dtype=tf.float32, name="Weight") # 权重
b = tf.Variable(1.0, dtype=tf.float32, name="Bias") # 偏差
x = tf.placeholder(dtype=tf.float32, name="Input") # 输入
with tf.name_scope("Output"): # 输出的命名空间
y = W * x + b # 输出
# const = tf.constant(2.0) # 常量不需要初始化,变量需要初始化
# 定义保存日志的路径
path = "./log"
# 创建用于初始化所有变量(Variable)的操作
# 如果定义了变量,但没有初始化的操作,会报错
init = tf.global_variables_initializer()
# 创建 Session(会话)
with tf.Session() as sess:
sess.run(init) # 初始化变量
writer = tf.summary.FileWriter(path, sess.graph)
result = sess.run(y, {x: 3.0}) # 为 x 赋值 3
print("y = W * x + b,值为 {}".format(result)) # 打印 y = W * x + b 的值,就是 7
- JavaScript 编写的网页应用
- 通过浏览器就可以训练简单神经网络
- 训练过程可视化,高度可定制