2017-07-10 5 views
0

私はTensorFlowでトレーニングモデルを持っています(下記のコードを参照)。このTensorFlowコードで予測された 'y'または '出力'マトリックスを印刷するにはどうすればよいですか?

私のモデルを訓練した後、私の累積「テスト確度」は0.92357と表示されています。

私は以下のコードを与えられたモデルを訓練した後、予測された出力行列または 'y'をどのように出力しますか?

# x will be the input matrix flattened (28x29) 
x = tf.placeholder(tf.float32, [None, 812]) 

# Define the weights (initial value doesn't matter since these will be learned) 
W = tf.Variable(tf.random_uniform([812, 812], minval=0, dtype=tf.float32)) 
b = tf.Variable(tf.random_uniform([812], minval=0, dtype=tf.float32)) 

# Predict output matrix 
y = tf.nn.softmax(tf.matmul(x, W) + b) 

# Actual output matrix from the training set 
y_ = tf.placeholder(tf.float32, [None, 812]) 

# Calculate loss and optimize 
cross_entropy = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(labels=y_, logits=y)) 
train_step = tf.train.AdamOptimizer(0.025).minimize(cross_entropy) 

sess = tf.InteractiveSession() 
tf.global_variables_initializer().run() 

a, b = get_batch() 
train_len = len(a) 

correct_prediction = tf.equal(y_, y) 
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 

# Training 
for i in range(train_len): 
    batch_xs = a[i] 
    batch_ys = b[i] 
    _, loss, acc = sess.run([train_step, cross_entropy, accuracy], feed_dict={x: batch_xs, y_: batch_ys}) 
    print("Loss= " + "{:.6f}".format(loss) + " Accuracy= " + "{:.5f}".format(acc)) 

# Test trained model 
cumulative_accuracy = 0.0 
for i in range(train_len): 
    acc_batch_xs = a[i] 
    acc_batch_ys = b[i] 
    cumulative_accuracy += accuracy.eval(feed_dict={x: acc_batch_xs, y_: acc_batch_ys}) 
print("Test Accuracy= {}".format(cumulative_accuracy/train_len)) 

答えて

0

任意のテンソルオブジェクトの値が

tensorFlowObject.eval() 

そこで使用することによって得ることができる、あなたはy

の値を取得するために y.eval()を使用することができます
関連する問題