Eda*_*ame 31 neural-network deep-learning tensorflow
我正在学习TensorFlow,构建一个多层感知器模型.我正在研究一些例子:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/multilayer_perceptron.ipynb
然后,我在下面的代码中有一些问题:
def multilayer_perceptron(x, weights, biases):
:
:
pred = multilayer_perceptron(x, weights, biases)
:
:
with tf.Session() as sess:
sess.run(init)
:
correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print ("Accuracy:", accuracy.eval({x: X_test, y: y_test_onehot}))
Run Code Online (Sandbox Code Playgroud)
我想知道做什么tf.argmax(prod,1)和tf.argmax(y,1)意味着什么,返回(类型和价值)究竟是什么?并且是correct_prediction变量而不是实际值?
最后,我们如何从tf会话中获取y_test_prediction数组(输入数据时的预测结果X_test)?非常感谢!
小智 43
tf.argmax(input, axis=None, name=None, dimension=None)
Run Code Online (Sandbox Code Playgroud)
返回张量轴上具有最大值的索引.
输入是Tensor,轴描述输入Tensor的哪个轴要减少.对于矢量,使用axis = 0.
对于您的具体情况,让我们使用两个数组并演示这一点
pred = np.array([[31, 23, 4, 24, 27, 34],
[18, 3, 25, 0, 6, 35],
[28, 14, 33, 22, 20, 8],
[13, 30, 21, 19, 7, 9],
[16, 1, 26, 32, 2, 29],
[17, 12, 5, 11, 10, 15]])
y = np.array([[31, 23, 4, 24, 27, 34],
[18, 3, 25, 0, 6, 35],
[28, 14, 33, 22, 20, 8],
[13, 30, 21, 19, 7, 9],
[16, 1, 26, 32, 2, 29],
[17, 12, 5, 11, 10, 15]])
Run Code Online (Sandbox Code Playgroud)
评估tf.argmax(pred, 1)给出了评估会给出的张量array([5, 5, 2, 1, 3, 0])
评估tf.argmax(y, 1)给出了评估会给出的张量array([5, 5, 2, 1, 3, 0])
tf.equal(x, y, name=None) takes two tensors(x and y) as inputs and returns the truth value of (x == y) element-wise.
Run Code Online (Sandbox Code Playgroud)
按照我们的例子,tf.equal(tf.argmax(pred, 1),tf.argmax(y, 1))返回一个评估将给出的张量array(1,1,1,1,1,1).
correct_prediction是一个张量,其评估将给出0和1的1-D数组
y_test_prediction可以通过执行获得 pred = tf.argmax(logits, 1)
可以通过以下链接访问tf.argmax和tf.equal的文档.
tf.argmax()https://www.tensorflow.org/api_docs/python/math_ops/sequence_comparison_and_indexing#argmax
tf.argmax(输入,轴=无,名称=无,维度=无)
返回张量跨轴最大值的索引。
对于具体情况,它接收pred作为 it'sinput和1as 的参数axis。该轴描述了要减少的输入张量的哪个轴。对于向量,使用 axis = 0。
示例:给定列表[2.11,1.0021,3.99,4.32]argmax 将返回3最高值的索引。
Correct_prediction是一个稍后将被评估的张量。它不是一个常规的 python 变量。它包含稍后计算值所需的信息。对于这种特定情况,它将成为另一个张量的一部分,并由onaccuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))进行评估。evalaccuracy.eval({x: X_test, y: y_test_onehot})
y_test_prediction应该是你的correct_prediction张量。
| 归档时间: |
|
| 查看次数: |
38119 次 |
| 最近记录: |