莫烦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 ...
随机推荐
- 《CSS世界》读书笔记(四)--宽度分离
<!-- <CSS世界>张鑫旭著 --> CSS流体布局下的宽度分离原则 所谓“宽度分离原则”,就是CSS中的width属性不与影响宽度的padding/border(有时候包 ...
- map的实际操作用并for_each遍历
#include<iostream> #include<map> #include<algorithm> #include<string> using ...
- rangeOfString 和 containsString 兼容iOS7处理
//查找字符串是否包含"心" NSString *str = @"每天都有好心情"; if ([str containsString:@"心" ...
- nginx的ip_hash负载均衡配置
upstream 4Asite{ server 192.168.16.99:8080 fail_timeout=15s; server 192.168.16.66:8080 fail_timeout= ...
- Linux内核 kmalloc, kzalloc & devm_kzalloc 区别【转】
本文转载自:https://blog.csdn.net/u014628531/article/details/50711409 首先,kzalloc()实现了kmalloc()+memset()的功能 ...
- Visual Studio 2017 配置导出/导入/重置
1.打开VS,按下面的快捷键呼出命令窗口 Ctrl+Alt+A 2.导入/导出/重置命令 Tools.ImportandExportSettings [/export:filename | /impo ...
- Lintcode481-Binary Tree Leaf Sum-Easy
481. Binary Tree Leaf Sum Given a binary tree, calculate the sum of leaves. Example Example 1: Input ...
- Robot Framework安装及配置
Robot Framework安装及配置 需要按照的软件有Python.WxPython.robot framework.robotframework-ride.robotframework-sele ...
- C#设置IE代理
public class IEProxySetting { public static bool UnsetProxy() { return SetProxy(null, null); } publi ...
- robot framework测试数据语法
Robot Framework通过文件的扩展名来选择使用何种解析器. 扩展名不分大小写. 可以识别的扩展名包括: HTML: .html, .htm 和 .xhtml TSV: .tsv 纯文本: . ...