Tensorflow机器学习入门——网络可视化TensorBoard
一、在代码中标记要显示的各种量
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的更多相关文章
- 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用
#训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...
- Tensorflow机器学习入门——MINIST数据集识别
参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html #自动下载并加载数据 from tensorflow.example ...
- Tensorflow机器学习入门——读取数据
TensorFlow 中可以通过三种方式读取数据: 一.通过feed_dict传递数据: input1 = tf.placeholder(tf.float32) input2 = tf.placeho ...
- Tensorflow机器学习入门——常量、变量、placeholder和基本运算
一.这里列出了tensorflow的一些基本函数,比较全面:https://blog.csdn.net/M_Z_G_Y/article/details/80523834 二.这里是tensortflo ...
- Tensorflow机器学习入门——ModuleNotFoundError: No module named 'tensorflow.keras'
这个bug的解决办法: # from tensorflow.keras import datasets, layers, models from tensorflow.python.keras imp ...
- Tensorflow机器学习入门——MINIST数据集识别(卷积神经网络)
#自动下载并加载数据 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_s ...
- Tensorflow机器学习入门——cifar10数据集的读取、展示与保存
基本信息 官网:http://www.cs.toronto.edu/~kriz/cifar.html 共60000张图片:50000张用于训练.10000张用于测试 图片大小为:32X32 数据集图片 ...
- 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 ...
- TensorFlow.NET机器学习入门【0】前言与目录
曾经学习过一段时间ML.NET的知识,ML.NET是微软提供的一套机器学习框架,相对于其他的一些机器学习框架,ML.NET侧重于消费现有的网络模型,不太好自定义自己的网络模型,底层实现也做了高度封装. ...
随机推荐
- Abaqus-GUI开发-RSG
目录 1. GUI开发简介 2. 目标和消息 2.1消息类型和消息ID 2.2消息映射 3. 控件创建 1. GUI开发简介 Abaqus GUI程序开发时,可以采用两种方式创建GUI图形界面. (1 ...
- leetcode 387
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- 基于MHA的MYSQL高可用方案
一.MHA 简介 MHA (Master High Availability )目前在 MySQL 高可用方面是一个相对成熟的解决方案,它由日本 DeNA 公司的 youshimaton 员工(现就职 ...
- 创建jsp文件时报错,"javax.servlet.http.HttpServlet" was not found on the Java)
原因: 创建jsp文件的步骤如下: 出现"javax.servlet.http.HttpServlet" was not found on the Java) 报错信息就是因为没有 ...
- windows server 2016系统激活
slmgr /ipk CB7KF-BWN84-R7R2Y-793K2-8XDDG slmgr /skms kms.03k.org slmgr /ato
- matlab学习记录
1.在命令框输入preferences,可以调整字体大小 2.产生正太分布函数 参考:https://blog.csdn.net/s334wuchunfangi/article/details/816 ...
- Euler Sums系列(三)
\[\Large\sum_{n=1}^{\infty}\frac{\left(H_{n}^{(2)}\right)^{2}}{n^{2}}=\frac{19}{24}\zeta(6)+\zeta^{2 ...
- 取消Oracle数据库密码期限 取消用户锁定
1.首先查用户被锁时间:sql>select username,account_status,lock_date from dba_users where username='SA'; 2.解锁 ...
- 线程池三种队列使用,SynchronousQueue,LinkedBlockingQueue,ArrayBlockingQueue
使用方法: private static ExecutorService cachedThreadPool = new ThreadPoolExecutor(4, Runtime.getRuntime ...
- AS布局篇
LinearLayout 线性布局 RelativeLayout 相对布局 FrameLayout 帧布局 AbsoluteLayout绝对布局 TableLayout 表格布局 GridLayout ...