我是新來tensorflow和我有一個快速的問題,這是我的模式,爲MNISTMNIST圖像預測模型
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))
所以在這裏我很困惑,即函數是否是一個模型或僅返回預測輸出。任何人都可以解釋,謝謝
此代碼是否運行?你能以一種讓我運行它的格式提供完整的代碼嗎? (例如Github) – finbarr
是的代碼工作,但我的問題是關於模型製作 –
這個功能據說是訓練模型以及輸入圖像的輸出嗎? –