莫烦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 ...
随机推荐
- 2019/4/11 wen 常用类2
- flutter key
随意点开一个Widget,就会发现,可以传递一个参数Key.那这个Key到底是干啥子,有什么用呢? Flutter是受React启发的,所以Virtual Dom的diff算法也参考过来了(应该是略有 ...
- 2、Kafka架构
Kafka架构图 1)Producer :消息生产者,就是向kafka broker发消息的客户端. 2)Consumer :消息消费者,向kafka broker取消息的客户端 3)Topic :可 ...
- 进程管理工具supervisor的使用
centos 6.5, python 2.6, supervisor 3.3.1: Linux下后台运行程序通常的做法是用nohub,然后配以进程的检测来实现服务式的操作,但其实有更好的选择super ...
- Golang实现杨辉三角
杨辉三角,也算是一个经典的题目了.就简单的说说. 写代码之前,先分析要做的东西的特点,找到规律,再把这个规律描述一下. 然后把这个描述翻译成编程语言,就可以说是编程了. 那么杨辉三角有什么特点? 首先 ...
- UI自动化(十)selenium定位
浏览器操作 1 2 3 4 5 6 7 8 # 刷新 driver.refresh() # 前进 driver.forward() # 后退 driver.back() 获取标签元素 ...
- 超简单的SpringBoot整合mybatis
1. 创建项目结构 2. 编写application.yml/application.properties配置文件 3. 启动类开启映射包扫描 4. 接口测试 创建项目结构 导入依赖 &l ...
- ipan笔记
// 对于mysql来说, 如果字段没有设置其 default值, 则会自动 设置 default值为null.同理没有设置not null, 则会自动允许null =yes // create ta ...
- JavaScript(数据类型、字符串操作)
JS基础 建议:一般情况下不在 head 标签中写 js 语句,因为该 js 语句会在 body 加载之前就执行,可能导致某些效果无效 // 单行注释 /*多行 * 注释*/ // 控制台输出语句 c ...
- Jmeter 分布式(Jmeter5.1版本)
一.修改负载机配置 vi /home/programs/apps/apache-jmeter-5.1/bin/jmeter.properties A.(先保证1099端口没有被占用,这里假设此端口未被 ...