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侧重于消费现有的网络模型,不太好自定义自己的网络模型,底层实现也做了高度封装. ...
随机推荐
- windows 10安装linux(ubuntu)子系统
windows10安装ubuntu子系统系统 之前一直在虚拟机中使用linux系统,但是不是很方便,后来发现windows下也有了linux系统.感觉还不错 1. 打开windows应用市场micro ...
- openresty-component
1.Array Var Nginx Module ArrayVarNginxModulelocation /foo { array_split ',' $arg_files to=$array; # ...
- 国密SM9算法C++实现(Linux)
首先参考 Linux下编译并使用miracl密码库 该博文在linux下编译Miracl库. 编译完了,自然是要用的,下面介绍两种在C程序中使用miracl库的方法. 方法一: 1. 源码编译完后的必 ...
- 【C语言】赋值运算中的类型转换
#include<stdio.h> int main() { int a, b; double x = 1.54; char ch; a = x; x = ; b = 'a'; ch = ...
- chrome 2行换行省略号 ... text-ellipse
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; 谷歌内部项目 ...
- django登陆界面报错InternalError at /admin/polls/question/add/
登陆界面报错信息如下: 改为输入英文,正确
- python练习:使用二分法查找求近似平方根,使用二分法查找求近似立方根。
python练习:使用二分法查找求近似平方根,使用二分法查找求近似立方根. 重难点:原理为一个数的平方根一定在,0到这个数之间,那么就对这之间的数,进行二分遍历.精确度的使用.通过最高值和最低值确定二 ...
- 关于idea2019.2.3版本中文控制台乱码问题
出现乱码后根据网上找的方法全都试过后还是显示乱码 更改VM Options为 -Dfile.encoding=UTF-8 添加备选字体 更改这两个文件 更改编码格式 以上这些方法全部设置 ...
- python 中的 int() 与 round
int(x):向下取整 round(x):超过 .5 则向上取整,否则向下取整
- UVA315 Network
割点的概念:对于无向图,删除这个点与其相连的边,整个图的连通分量个数增加. 对于无向图的tarjan算法,必须要设前驱~ 求割点的模板~ #include<cstdio> #include ...