介绍
这篇文章主要讲解了“如何使用tensorboard展示神经网络的图”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习”如何使用tensorboard展示神经网络的图”吧!
#,创建神经网络,,使用tensorboard 展示图 import tensorflow  as tf import numpy  as np import matplotlib.pyplot  as plt , #,若没有,pip install matplotlib #,定义一个神经层 def add_layer (in_size,输入,还以为,out_size, activation_function=None): ,,,# add one more layer 以及return 从而output of 却;能够层 ,,,with tf.name_scope(& # 39;层# 39;): ,,,,,,,with tf.name_scope(& # 39;重量# 39;): ,,,,,,,,,,,Weights =, tf.Variable (tf.random_normal ([out_size in_size也])、name=& # 39; w # 39;) ,,,,,,,with tf.name_scope(& # 39;偏见# 39;): ,,,,,,,,,,,biases =, tf.Variable (tf.zeros ([1, out_size]), +, 0.1, name=& # 39; b # 39;) ,,,,,,,with tf.name_scope (& # 39; Wx_plus_b& # 39;): ,,,,,,,,,,,Wx_plus_b =, tf.matmul(输入,,权重),+,偏见 ,,,,,,,if activation_function is 没有: ,,,,,,,,,,,outputs =Wx_plus_b ,,,,,,,其他的: ,,,,,,,,,,,outputs =, activation_function (Wx_plus_b) # # # ,,,,,,,return 输出 # make up  some real 数据 时间=x_data np.linspace (1,, 1,, 300) (:,, np.newaxis],, #, x_data值为1到1之间,有300个单位(例子),再加一个维度newaxis,即300行* newaxis列 时间=noise np.random.normal (0.05 0,,,, x_data.shape),, #,均值为0。方差为0.05,格式和x_data一样 时间=y_data np.square (x_data),安康;0.5,+,噪音 # define placeholder  for inputs 用网络 with tf.name_scope(& # 39;输入# 39;): ,,,xs =, tf.placeholder (tf.float32,,没有,,1,name=& # 39; x_input1& # 39;),, #,没有表示无论给多少个例子都行 ,,,ys =, tf.placeholder (tf.float32,,没有,,1,name=& # 39; y_input1& # 39;) #,add hidden 层 时间=l1 add_layer (x,, 1,,,, activation_function=tf.nn.relu) #,add output 层 时间=prediction add_layer (l1,,,, 1,, activation_function=没有) #,error 结构;prediction 以及real 数据 with tf.name_scope(& # 39;损失# 39;): ,,,loss =, tf.reduce_mean ( ,,,,,,,tf.reduce_sum (tf.square (ys 安康;预测),reduction_indices=[1])),, #,对每个例子进行求和并取平均值,reduction_indices=[1]指按行求和 with tf.name_scope(& # 39;火车# 39;): ,,,train_step =, tf.train.GradientDescentOptimizer (0.1) .minimize(损失),,#,以0.1的学习效率对误差进行更正和提升 #两种初始化的方式 # init =, tf.initialize_all_variables () 时间=init tf.global_variables_initializer () 时间=sess tf.Session () sess.run (init) #把整个框架加载到一个文件中去,再从文件中加载出来放到浏览器中查看 #作家=tf.train.SummaryWriter(“/叭罩?sess.graph) #首先找到tensorboard.exe的路径并进入c:蟒蛇\脚本,执行tensorboard.exe ——logdir=代码生成的图像的路径(不能带中文) 作家=tf.summary.FileWriter(“. ./. ./日志/?sess.graph) 时间=fig plt.figure () 时间=ax fig.add_subplot (1, 1, 1) ax.scatter (x_data, y_data) plt.ion () plt.show(),,, #显示()是一次性的展示,为了使连续的展示,加入plt.ion () for 小姐:拷贝范围(1000): ,,,sess.run (train_step, feed_dict={xs:, x_data,, y,, y_data}) ,,,if 小姐:%,50,==,0: ,,,,,,,#,用阅读,step improment 显示实际点的数据 ,,,,,,,#,打印(sess.run(损失,feed_dict =, {xs: x_data y: y_data})) ,,,,,,,试一试: ,,,,,,,,,,,#,每次划线前抹除上一条线,抹除线的第一条线,由于行只有一条线,则为[0],第一次没有线 ,,,,,,,,,,,ax.lines.remove([0]行) ,,,,,,,except 例外: ,,,,,,,,,,, ,,,,,,,#,显示预测数据 ,,,,,,,prediction_value =, sess.run(预测,feed_dict={xs:, x_data}) null null null null null如何使用tensorboard展示神经网络的图