TensorFlow TensorBoard工具:网络结构可视化


tensorboard展示网络结构

代码

import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datatf
.compat.v1.disable_eager_execution()#载入数据集mnist=input_data.read_data_sets("MNIST_data",one_hot=True)
#每个批次大小batch_size=100#计算一共有多少个批次n_bath=mnist.train.num_examples // batch_sizeprint(n_bath)with tf
.name_scope('input'):    #定义两个placeholder    
x=tf.compat.v1.placeholder(tf.float32,[None,784],name='x-input')    y=tf
.compat.v1.placeholder(tf.float32,[None,10],name='y-input')with tf.name_scope('layer'):    
#创建一个简单的神经网络    with tf.name_scope('wights'):        W=tf.Variable(tf.zeros([784,10]),name='W')    
with tf.name_scope('biases'):        b=tf.Variable(tf.zeros([10]),name='b')    
with tf.name_scope('wx_plus_b'):        wx_plus_b=tf.matmul(x,W)+b    with tf.name_scope('softmax'):        
prediction=tf.nn.softmax(wx_plus_b)with tf.name_scope('loss'):    
#二次代价函数    loss=tf.reduce_mean(tf.square(y-prediction))with tf.name_scope('train'):    
#梯度下降    train_step=tf.compat.v1.train.GradientDescentOptimizer(0.2)
.minimize(loss)#初始化变量init=tf.compat.v1.global_variables_initializer()with tf.name_scope('accuracy'):    
with tf.name_scope('correct_prediction'):        #结果存放在一个布尔型列表中        
#返回的是一系列的True或False argmax返回一维张量中最大的值所在的位置,对比两个最大位置是否一致        
correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))    with tf.name_scope('accuracy'):        
#求准确率        #cast:将布尔类型转换为float,将True为1.0,False为0,然后求平均值        
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))with tf.compat.v1.Session() as sess:    
sess.run(init)    writer=tf.compat.v1.summary.FileWriter('logs/',sess.graph)    for epoch in range(1):        
for batch in range(n_bath):            #获得一批次的数据,batch_xs为图片,batch_ys为图片标签            
batch_xs,batch_ys=mnist.train.next_batch(batch_size)            #进行训练            
sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})        #训练完一遍后,测试下准确率的变化        
acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})        
print("Iter "+str(epoch)+",Testing Accuracy "+str(acc))1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.
20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.
55.56.57.58.59.60.61.62.63.64.65.66.

会生成logs/目录,并且目录下的文件我们需要这样子打开


打开图的方法

1.找到“tensorboard.exe”所在目录(找不到直接用搜索,一般在python运行环境目录中),输入cmd回车打开。

Tensorflow-tensorboard展示网络结构_梯度下降

2.找到运行程序的日志输出路径(一般在项目目录中),复制路径地址。

3.cmd框中键入命令:tensorboard --logdir=日志路径地址,回车,把红框内的网址复制到浏览器打开,搞定。


Tensorflow-tensorboard展示网络结构_数据_02

图形化展示

点击对应的模块,会展示详细的数据信息以及相应的结构展示

Tensorflow-tensorboard展示网络结构_Tensorflow_03

   

   



免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空