码迷,mamicode.com
首页 > 其他好文 > 详细

Tensorflow--TensorflowBoard

时间:2020-02-19 00:36:47      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:iter   ace   variables   png   src   inf   init   图片   variable   

基本符号

技术图片

 

 代码:

# -*- 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

运行结果:

y = W * x + b,值为 7.0

技术图片

 cmd:

tensorboard --logdir=log

运行结果:

TensorBoard 1.11.0 at http://DESKTOP-I0SJT3T:6006 (Press CTRL+C to quit)

技术图片

Tensorflow--TensorflowBoard

标签:iter   ace   variables   png   src   inf   init   图片   variable   

原文地址:https://www.cnblogs.com/SCCQ/p/12329330.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!