TensorFlow——TensorBoard可视化工具

1、tensorboard

"-----------------矩阵相乘----------------"
import tensorflow as tf

with tf.name_scope('graph') as scope:
    matrix1 = tf.constant([[3., 3.]], name='matrix1')
    matrix2 = tf.constant([[2.], [2.]], name='matrix2')
    product = tf.matmul(matrix1, matrix2, name='product')

sess = tf.Session()
init = tf.global_variables_initializer()
writer = tf.summary.FileWriter("./logs", sess.graph)
sess.run(init)
print(sess.run(product))

# "----------------线性拟合----------------"
# import tensorflow as tf
# import numpy as np
#
# ## prepare the original data
# with tf.name_scope('data'):
#      x_data = np.random.rand(100).astype(np.float32)
#      y_data = 0.3 * x_data + 0.1
# ##creat parameters
# with tf.name_scope('parameters'):
#      with tf.name_scope('weights'):
#          weight = tf.Variable(tf.random_uniform([1],-1.0,1.0))
#          tf.summary.histogram('weight', weight)
#      with tf.name_scope('biases'):
#          bias = tf.Variable(tf.zeros([1]))
#          tf.summary.histogram('bias',bias)
#
# #预测y值_
# with tf.name_scope('y_prediction'):
#      y_prediction = weight * x_data + bias
#
# #计算loss
# with tf.name_scope('loss'):
#      loss = tf.reduce_mean(tf.square(y_data - y_prediction))
#      tf.summary.scalar('loss',loss)
#
# #创建优化器
# optimizer = tf.train.GradientDescentOptimizer(0.5)
#
# #最小损失率
# with tf.name_scope('train'):
#      train = optimizer.minimize(loss)
#
# #所有变量初始化
# with tf.name_scope('init'):
#      init = tf.global_variables_initializer()
# #创建会话
# sess = tf.Session()
#
# #合并所有信息
# merged = tf.summary.merge_all()
#
# #保存图
# writer = tf.summary.FileWriter("logs/", sess.graph)
# sess.run(init)
#
# #训练
# for step  in  range(101):
#     sess.run(train)
#     rs = sess.run(merged)
#     writer.add_summary(rs, step)
#     print("loss: %df"%sess.run(loss), "step: %d"%step)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值