Tensorflow细节-P62-完整的神经网络样例程序
这样是比较好的一个summary命名
(1)'networks'、'layer_%d' % n_layer、'weights'三个命名空间相互叠加
(2)
if i % 50 == 0:
result = sess.run(merged, feed_dict={xs: x_data, ys: y_data})
writer.add_summary(result, i)
逐步写入的程序如上面所示
(3)最后的tensorboard图还是比较完美的

import numpy as np
import tensorflow as tf
def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
layer_name = 'layer_%d' % n_layer
with tf.name_scope(layer_name):
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
tf.summary.histogram('weights', Weights)
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='B')
tf.summary.histogram('biases', biases)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
x_data = np.linspace(-1, 1, 300)[:, np.newaxis]
noise = np.random.normal(0, 0.05, x_data.shape)
y_data = 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')
with tf.name_scope('networks'):
l1 = add_layer(xs, 1, 10, 1, activation_function=tf.nn.relu)
prediction = add_layer(l1, 10, 1, 2, activation_function=None)
with tf.name_scope('losses'):
loss = tf.reduce_mean(tf.square(ys - prediction))
tf.summary.scalar('Loss', loss)
# train框,其中包含梯度下降步骤和权重更新步骤
with tf.name_scope('train'):
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
init = tf.global_variables_initializer()
merged = tf.summary.merge_all()
with tf.Session() as sess:
writer = tf.summary.FileWriter('path/', tf.get_default_graph())
sess.run(init)
for i in range(10001):
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)
writer.close()
Tensorflow细节-P62-完整的神经网络样例程序的更多相关文章
- 吴裕雄 python 神经网络——TensorFlow 完整神经网络样例程序
import tensorflow as tf from numpy.random import RandomState batch_size = 8 w1= tf.Variable(tf.rando ...
- Nginx完整配置配置样例【官方版】
我们主要参考nginx官方给出的完整配置的样例: https://www.nginx.com/resources/wiki/start/topics/examples/full/# 完整摘录如下: n ...
- CountDownTimer完整具体演示样例
MainActivity例如以下: package cc.cv; import android.os.Bundle; import android.os.CountDownTimer; import ...
- 在Ubuntu下构建Bullet以及执行Bullet的样例程序
在Ubuntu下构建Bullet以及执行Bullet的样例程序 1.找到Bullet的下载页,地址是:https://code.google.com/p/bullet/downloads/list 2 ...
- SNF快速开发平台MVC-各种级联绑定方式,演示样例程序(包含表单和表格控件)
做了这么多项目,经常会使用到级联.联动的情况. 如:省.市.县.区.一级分类.二级分类.三级分类.仓库.货位. 方式:有表单需要做级联的,还是表格行上需要做级联操作的. 实现:实现方法也有很多种方式. ...
- Tuxedo安装、配置、以及演示样例程序 (学习网址)
Tuxedo安装.配置.以及演示样例程序 (学习网址): 1.http://liu9403.iteye.com/blog/1415684 2.http://www.cnblogs.com/fnng/a ...
- Java读取Excel文件(包括xls和xlsx)的样例程序
样例程序如下所示,其中: parseXls()函数依赖于jxl,只能读取xls格式文件: parseExcel()函数依赖于apache poi,能够读取xls和xlsx两种格式的文件. jxl的依赖 ...
- 吴裕雄 python 神经网络——TensorFlow TFRecord样例程序
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
- 80、tensorflow最佳实践样例程序
''' Created on Apr 21, 2017 @author: P0079482 ''' #-*- coding:utf-8 -*- import tensorflow as tf #定义神 ...
随机推荐
- C语言单链表简单实现(简单程序复杂化)
PS: goto还是很好玩的. #include <stdio.h> #include <stdlib.h> typedef struct _node{ int value; ...
- DjangoRestFramework学习二之序列化组件、视图组件
本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组件 首先按照restful规范咱们创建一些api接口,按照下面这些形式写吧: ...
- TZOJ5697: 数据结构实验:归并排序
#include<stdio.h> #include<stdlib.h> void merge(int a[], int start,int mid,int end) { )) ...
- 协议——IIC
I²C即Inter-Integrated Circuit(集成电路总线),它是一种串行通信总线,使用多主从架构,由飞利浦公司在1980年代设计出来的一种简单.双向.二线制总线标准.多用于主机和从机在数 ...
- rsync 使用
rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件. rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分, ...
- JSON C# Class Generator
http://www.xamasoft.com/json-class-generator/ JsonHelper.cs using System; using System.Collections.G ...
- mybatis-plus代码生成,实体类不生成父类属性
一.参考文档: 官方文档其实说的很清楚了,可能有个别地方有点不太清楚. mybatis-plus官方: https://mp.baomidou.com/guide/generator.html 模版引 ...
- PHP敏感信息脱敏函数
测试 $name = '王刚'; $mobile = '13817558198'; $name = desensitize($name,1,1); $mobile = desensitize($mob ...
- Wenaox 一款轻量性能好的微信小程序状态管理库
感慨一下!!! 从开始开发 wenaox 从开始到现在,,时不时更新一下,改一改 bug,却发现已经快 1 年了 orz 虽然很少人用 hhh,但偶尔也会有人提一些问题,我就知道还有人用的~ 感兴趣的 ...
- Java 之 函数式接口
函数式接口 一.概念 函数式接口在 java 中是指:有且仅有一个抽象方法的接口. 函数式接口,即适用于函数式编程场景的接口. 而Java中的函数式编程体现就是Lambda,所以函数式接口就是可以适用 ...