我是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)行返回。

这样,该函数将返回模型的输出层,这将用于进行预测。可以将其称为“模型”,但我认为最好将会话变量称为“模型”。

08-19 20:28