本笔记主要讲如何运用tensorflow看自己创建网络的结构。
- 可以通过with tf.name_scope(‘weights’):来添加模块的名称,并且with可以嵌套。对于变量也可以通过name参数来定义名字。然后在终端里输入
tensorboard –logdir=logs,再在浏览器里打开相应地址即可。
from __future__ import print_function
import tensorflow as tf
def add_layer(inputs, in_size, out_size, activation_function=None):
# add one more layer and return the output of this layer
with tf.name_scope('layer'):
with tf.name_scope('weights'):
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
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)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b, )
return outputs