本港台开奖现场直播 j2开奖直播报码现场
当前位置: 新闻频道 > IT新闻 >

wzatv:【组图】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技(7)

时间:2017-03-10 02:41来源:118论坛 作者:118KJ 点击:
TensorFlow给你的不仅仅是这些,有一个特别棒的工具TensorBoard能够可视化训练过程中的信息,能让人直观的感受,当然需要一些简单的配置: 写入Graph writ

TensorFlow给你的不仅仅是这些,有一个特别棒的工具TensorBoard能够可视化训练过程中的信息,能让人直观的感受,当然需要一些简单的配置:

写入Graph

  writer = tf.summary.FileWriter("/tmp/mnist_demo/1") writer.add_graph(sess.graph)

wzatv:【j2开奖】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技

这里虽然能够可视化Graph,却感觉很杂乱,我们可以通过给一些node增加name,scope,让图变得更好看点:

  def conv_layer(input, channels_in, channels_out, name="conv"): with tf.name_scope(name): w = tf.Variable(tf.zeros([5, 5, channels_in, channels_out]), name="W") b = tf.Variable(tf.zeros([channels_out]), name="B") conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding="SAME") act = tf.nn.relu(conv + b) return tf.nn.max_pool(act, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")def fc_layer(input, channels_in, channels_out, name="fc"): with tf.name_scope(name): w = tf.Variable(tf.zeros([channels_in, channels_out]), name="W") b = tf.Variable(tf.zeros([channels_out]), name="B") return tf.nn.relu(tf.matmul(input, w) + b)# Setup placeholders, and reshape the data x = tf.placeholder(tf.float32, shape=[None, 784], name="x") x_image = tf.reshape(x, [-1, 28, 28, 1]) y = tf.placeholder(tf.float32, shape=[None, 10], name="labels")conv1 = conv_layer(x_image, 1, 32, "conv1") conv2 = conv_layer(conv1, 32, 64, "conv2")flattened = tf.reshape(conv2, [-1, 7 * 7 * 64]) fc1 = fc_layer(flattened, 7 * 7 * 64, 1024, "fc1") logits = fc_layer(fc1, 1024, 10, "fc2")with tf.name_scope("xent"): xent = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))with tf.name_scope("train"): train_step = tf.train.AdamOptimizer(1e-4).minimize(xent)with tf.name_scope("accuracy"): correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))writer = tf.summary.FileWriter("/tmp/mnist_demo/2") writer.add_graph(sess.graph)

wzatv:【j2开奖】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技

通过TensorFlow的api,收集更多的数据记录显示在TensorBoard中:

  tf.summary.scalar('cross_entropy', xent) tf.summary.scalar('accuracy', accuracy)tf.summary.image('input', x_image, 3)

wzatv:【j2开奖】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技

修改Conv的代码,将Weight,bias,act加入到histogram中:

  def conv_layer(input, channels_in, channels_out, name="conv"): with tf.name_scope(name): w = tf.Variable(tf.zeros([5, 5, channels_in, channels_out]), name="W") b = tf.Variable(tf.zeros([channels_out]), name="B") conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding="SAME") act = tf.nn.relu(conv + b) tf.summary.histogram("weights", w) tf.summary.histogram("biases", b) tf.summary.histogram("activations", act) return tf.nn.max_pool(act, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")

配置将训练过程中的数据写入:

(责任编辑:本港台直播)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
推荐内容