首先,我在Python和Tensorflow中都很新。 我试图链接的演示:https://www.tensorflow.org/get_started/mnist/beginners 它运行良好。 但是,我想调试(或记录)一些占位符的值,这些变量在运行Session.run()时发生了变化。我Tensorflow:在会话运行时输出值
请你告诉我的方式来“调试”或登录时,会话运行在循环? 这是我的代码
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("mnist/", one_hot=True)
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y1 = tf.add(tf.matmul(x,W),b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
cross_entropy1 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y1, y_))
train_step = tf.train.GradientDescentOptimizer(0.05).minimize(cross_entropy1)
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
for _ in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.argmax(y,1), feed_dict={x: mnist.test.images, y_: mnist.test.labels})
在该脚本中,我想记录y和tf.argmax的数值(y,1),用于处理每一个测试图像。
你见过这个[幻灯片](https://wookayin.github.io/tensorflow-talk-debugging/#1)吗? – xxi
谢谢@xxi,这是一个有趣的幻灯片。我现在会尝试。 – nguyenhoai890