[英]MNIST image prediction model
我是tensorflow的新手,我有一個快速的問題,這是我的MNIST模型的代碼
def neural_network_model(data):
hidden_1_layer = {'weights': tf.Variable(tf.random_normal([784, n_nodes_hl1])),
'biases': tf.Variable(tf.random_normal([n_nodes_hl1]))}
hidden_2_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),
'biases': tf.Variable(tf.random_normal([n_nodes_hl2]))}
hidden_3_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),
'biases': tf.Variable(tf.random_normal([n_nodes_hl3]))}
output_layer = {'weights': tf.Variable(tf.random_normal([n_nodes_hl3, n_classes])),
'biases': tf.Variable(tf.random_normal([n_classes])), }
l1 = tf.add(
tf.matmul(
data,
hidden_1_layer['weights']),
hidden_1_layer['biases'])
l1 = tf.nn.relu(l1)
l2 = tf.add(
tf.matmul(
l1,
hidden_2_layer['weights']),
hidden_2_layer['biases'])
l2 = tf.nn.relu(l2)
l3 = tf.add(
tf.matmul(
l2,
hidden_3_layer['weights']),
hidden_3_layer['biases'])
l3 = tf.nn.relu(l3)
output = tf.matmul(l3, output_layer['weights']) + output_layer['biases']
return output
我的問題是,此函數是否表示輸入“數據”的輸出值? 還是此功能代表將在訓練后用於測試/預測圖像的完整模型?
這是我用於預測特定圖像的代碼:
prediction=neural_network_model(mnist_training_data_set)
p=tf.argmax(prediction,1)
print(p.eval(feed_dict={x: i}, session=sess))
所以在這里我很困惑,無論該函數是模型還是僅返回預測的輸出。 誰能解釋,謝謝
此函數創建模型並將其添加到計算圖。 預測的輸出將通過p.eval(feed_dict={x: i}, session=sess)
行返回。
這樣,該函數將返回模型的輸出層,這將用於進行預測。 可以將其稱為“模型”,但我認為最好將會話變量稱為“模型”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.