莫烦tensorflow(6)-tensorboard
import tensorflow as tf
import numpy as np
def add_layer(inputs,in_size,out_size,n_layer,activation_function=None):
# add one more layer and return the output of this layer
layer_name = 'layer%s' % n_layer
with tf.name_scope('layer'):
with tf.name_scope('weights'):
Weights = tf.Variable(tf.random_normal([in_size,out_size]),name='W')
tf.summary.histogram(layer_name+'/weights',Weights)
with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros([1,out_size]) + 0.1,name='b')
with tf.name_scope('Wx_plus_b'):
Wx_plus_b = tf.add(tf.matmul(inputs,Weights),biases)
tf.summary.histogram(layer_name+'/biases',biases)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
tf.summary.histogram(layer_name+'/outputs',outputs)
return outputs
# make up some real data
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')
# create hidden layer
l1 = add_layer(xs,1,10,1,activation_function=tf.nn.relu)
# create output layer
prediction = add_layer(l1,10,1,2,activation_function=None)
# the error between prediction adn real data
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),reduction_indices=[1]))
tf.summary.scalar('loss',loss)
with tf.name_scope('train'):
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
sess = tf.Session()
merged = tf.summary.merge_all()
writer = tf.summary.FileWriter("logs/",sess.graph)
# import step
sess.run(tf.global_variables_initializer())
for i in range(1000):
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)
莫烦tensorflow(6)-tensorboard的更多相关文章
- 莫烦tensorflow(9)-Save&Restore
import tensorflow as tfimport numpy as np ##save to file#rember to define the same dtype and shape w ...
- 莫烦tensorflow(8)-CNN
import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data#number 1 to 10 dat ...
- 莫烦tensorflow(7)-mnist
import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data#number 1 to 10 dat ...
- 莫烦tensorflow(5)-训练二次函数模型并用matplotlib可视化
import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt def add_layer(inputs,in_siz ...
- 莫烦tensorflow(4)-placeholder
import tensorflow as tf input1 = tf.placeholder(tf.float32)input2 = tf.placeholder(tf.float32) outpu ...
- 莫烦tensorflow(3)-Variable
import tensorflow as tf state = tf.Variable(0,name='counter') one = tf.constant(1) new_value = tf.ad ...
- 莫烦tensorflow(2)-Session
import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2' import tensorflow as tfmatrix1 = tf.constant([[3,3] ...
- 莫烦tensorflow(1)-训练线性函数模型
import tensorflow as tfimport numpy as np #create datax_data = np.random.rand(100).astype(np.float32 ...
- tensorflow学习笔记-bili莫烦
bilibili莫烦tensorflow视频教程学习笔记 1.初次使用Tensorflow实现一元线性回归 # 屏蔽警告 import os os.environ[' import numpy as ...
随机推荐
- openGL学习----光照
0.光照处理时候,向量点乘一定要是标准化后的单位向量!!! 1.冯氏光照模型:光照=环境光+漫反射+镜面反射 vec3 result = ambient + diffuse + specular; 一 ...
- 51Nod 算法马拉松12 移数博弈
点进去发现并不是博弈QAQ 一开始考虑单调队列什么乱七八糟的发现根本做不出来 (没错我一直在想枚举最大值求次大值QAQ 不妨换个思路: 我们考虑枚举次大值求最大值 设当前为now, 设now之前第一个 ...
- SSM项目思路整合NEW
#首先进行项目思路整体分析,具体包括哪些模块,如何实现等: 一)搭建环境 1.导包: (Spring核心包4个 + 面向切面的包4个 + SpringJDBC和事务的包各一个, SpringMVC两个 ...
- Oracle 11gR2 用户重命名(rename user)
Oracle 11.2.0.2里新增了一个新特性——用户重命名(Rename User),在这个版本之前要想重命名用户,需要按用户导出,再fromuser touser(imp)或remap_sc ...
- Matlab Code for Visualize the Tracking Results of OTB100 dataset
Matlab Code for Visualize the Tracking Results of OTB100 dataset 2018-11-12 17:06:21 %把所有tracker的结果画 ...
- 解决 ln -s 软链接产生的Too many levels of symbolic links错误
参考: ln -s 软链接产生Too many levels of symbolic links错误 解决 ln -s 软链接产生的Too many levels of symbolic links错 ...
- gets() 与 scanf() 的小尴尬
gets() 与 scanf() 函数相处呢有点小尴尬的,就是 gets() 在 scanf() 后边就爱捣乱.为什么呢,先了解它们两者之间的异同: 同: 都是可以接受连续的字符数据 并在字符结束后自 ...
- MapReduce 踩坑 - hadoop No FileSystem for scheme: file/hdfs
一.场景 hadoop-3.0.2 + hbase-2.0.0 一个mapreduce任务,在IDEA下本地提交到hadoop集群可以正常运行. 现在需要将IDEA本地项目通过maven打成jar包, ...
- 【七】jquery之属性attr、 removeAttr、prop[全选全不选及反选]
全选全不选 界面: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- while循环和递归
这个问题是在数据结构的二叉树添加结点的时候碰见 添加新结点的时候可以用while循环自身解决(这里这个方式更好) 也可以用递归解决 递归就像小明去楼顶取东西 ,从一楼开始爬,看,不是的,继续爬,每层 ...