一、在代码中标记要显示的各种量

tensorboard各函数的作用和用法请参考:https://www.cnblogs.com/lyc-seu/p/8647792.html

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
#设置当前工作目录
os.chdir(r'H:\Notepad\Tensorflow') def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
layer_name = 'layer%s' % n_layer
with tf.name_scope(layer_name): Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b, ) #histogram用来显示训练过程中变量的分布情况
tf.summary.histogram(layer_name + '/weights', Weights)
tf.summary.histogram(layer_name + '/biases', biases)
tf.summary.histogram(layer_name + '/outputs', outputs) return outputs #数据
x_data = np.linspace(-1,1,300)[:, np.newaxis]
noise = np.random.normal(0, 0.05, x_data.shape)
y_data = 5*np.square(x_data) - 0.5 + noise #输入
with tf.name_scope('inputs'):
xs = tf.placeholder(tf.float32, [None, 1], name='x_input')
ys = tf.placeholder(tf.float32, [None, 1], name='y_input') #3层网络
l1 = add_layer(xs, 1, 10, 1,activation_function=tf.nn.relu)
l2 = add_layer(l1, 10, 10,2, activation_function=tf.nn.relu)
prediction = add_layer(l2, 10, 1,3, activation_function=None) #损失与训练
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),
reduction_indices=[1]))
tf.summary.scalar('loss-haha', loss)
with tf.name_scope('train'):
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss) #运行
init = tf.global_variables_initializer()
#merge_all 可以将所有summary全部保存到磁盘,以便tensorboard显示。
merged = tf.summary.merge_all()
with tf.Session() as sess:
sess.run(init)
  #FileWriter指定一个文件用来保存图。可以调用其add_summary()方法将训练过程数据保存在filewriter指定的文件中
writer = tf.summary.FileWriter("logs/", sess.graph)#输出Graph
for i in range(10000):
sess.run(train_step, feed_dict={xs: x_data, ys: y_data})
if i % 50 == 0:
result = sess.run(merged,feed_dict={xs: x_data, ys: y_data})
writer.add_summary(result, i)

二、在log文件夹所在目录打开cmd,并输入‘     tensorboard --logdir=logs     ’

三、在Google Chrome浏览器中输入cmd中给出的网址: http://Fengqiao_x:6006

Tensorflow机器学习入门——网络可视化TensorBoard的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用

    #训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...

  2. Tensorflow机器学习入门——MINIST数据集识别

    参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html #自动下载并加载数据 from tensorflow.example ...

  3. Tensorflow机器学习入门——读取数据

    TensorFlow 中可以通过三种方式读取数据: 一.通过feed_dict传递数据: input1 = tf.placeholder(tf.float32) input2 = tf.placeho ...

  4. Tensorflow机器学习入门——常量、变量、placeholder和基本运算

    一.这里列出了tensorflow的一些基本函数,比较全面:https://blog.csdn.net/M_Z_G_Y/article/details/80523834 二.这里是tensortflo ...

  5. Tensorflow机器学习入门——ModuleNotFoundError: No module named 'tensorflow.keras'

    这个bug的解决办法: # from tensorflow.keras import datasets, layers, models from tensorflow.python.keras imp ...

  6. Tensorflow机器学习入门——MINIST数据集识别(卷积神经网络)

    #自动下载并加载数据 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_s ...

  7. Tensorflow机器学习入门——cifar10数据集的读取、展示与保存

    基本信息 官网:http://www.cs.toronto.edu/~kriz/cifar.html 共60000张图片:50000张用于训练.10000张用于测试 图片大小为:32X32 数据集图片 ...

  8. Tensorflow机器学习入门——AttributeError: module 'scipy.misc' has no attribute 'toimage'

    这个bug的解决办法: import cv2 # scipy.misc.toimage(image_array).save('cifar10_data/raw/%d.jpg' % i) cv2.imw ...

  9. TensorFlow.NET机器学习入门【0】前言与目录

    曾经学习过一段时间ML.NET的知识,ML.NET是微软提供的一套机器学习框架,相对于其他的一些机器学习框架,ML.NET侧重于消费现有的网络模型,不太好自定义自己的网络模型,底层实现也做了高度封装. ...

随机推荐

  1. k8s Learning Notes

    Kubernetes - 组件介绍 MESOS APACHE 分布式资源管理框架 2019-5 Twitter > Kubernetes Docker Swarm 2019-07 阿里云宣布 D ...

  2. js 根据data-i 降序排列

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 7、源与值(Source/Values)

    学习目录:树莓派学习之路-GPIO Zero 官网地址:https://gpiozero.readthedocs.io/en/stable/source_values.html 环境:UbuntuMe ...

  4. VMware安装EVE

    众所周知,EVE是一个非常强大的仿真环境,能给我们学习带来很大的帮助,这里主要简单记录一下安装在VMware下安装EVE的过程. 1.准备: 我安装的VMware是WORKSTATION 12 PRO ...

  5. 使用node查询数据库(mysql)时,日期格式不对的问题。

    https://blog.csdn.net/chanlingmai5374/article/details/93190983 1.问题场景 数据库里存了 datetime.但 Node 查询出来是这样 ...

  6. 牛客小白赛4 C题

    乘法逆元: 一个数a 乘上 b,在mod之后再还原成本来的数 a 这里就要用到乘法逆元,(a*b)%mod*inv(b,mod)==a ll exgcd(ll a,ll b,ll &x,ll ...

  7. jenkins介绍及部署tomcat环境、部署Maven项目及密码忘记修改

    安装配置jenkins: jenkins安装方式一:war包 1.先安装tomcat将jenkins,war直接放到webapps目录下 2.通过java-jar jenkins.war --http ...

  8. SpringCloud全家桶学习之路由网关----Zuul(六)

    一.Zuul概述 (1)Zuul是什么? Zuul包含了对请求的路由和过滤的两个最主要的功能,其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础:而过滤功能则负责对请求的 ...

  9. Spring Boot 开发 WebService 服务

    WebService 虽然现在大部分互联网企业不太提倡使用,但在以第三方接口为主导的市场,对方来什么接口你还得用什么接口,不可能把接口重写了.例如大部分传统的大型企业都在用 WebService,并且 ...

  10. Euler Sums系列(四)

    \[\Large\displaystyle \sum_{n=1}^\infty (-1)^n \frac{H_n}{2n+1}=\mathbf{G}-\frac{\pi}{2}\ln(2)\] \(\ ...