首先,我在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