我训练了一个关于mnist数据集的logistic回归模型,这些是重要的变量.
# tf Graph Input
x = tf.placeholder(tf.float32, [None, 784]) # mnist data image of shape 28*28=784
y = tf.placeholder(tf.float32, [None, 10]) # 0-9 digits recognition => 10 classes
# set model weights
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
# construct model
logits = tf.matmul(x, W) + b
pred = tf.nn.softmax(logits) # Softmax
# minimize error using cross entropy
cost = tf.reduce_mean(-tf.reduce_sum(y * tf.log(pred), reduction_indices=1))
# Gradient Descent
optimizer = tf.train.GradientDescentOptimizer(FLAGS.learning_rate).minimize(cost)现在我所做的就是创建一个名为adversarial的数组,该数组由稍微改变的图像组成,然后反馈到模型中,这样它就可以进行预测了。
如果我做下面的事..。
classification_adversarial = sess.run(tf.argmax(pred, 1), feed_dict={x:adversarial})
print(classification_adversarial)
>> [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]我得到了模型预测的结果。这是预期的输出,模型认为图像是6s。
无论如何,对于这些图像中的每一张,我都希望显示一个accuracy。所以,如果我给出一张像adversarial.reshape((1, 784))这样的图像,我想让模型告诉我它的预测有多准确,百分比有多大。
我试着用下面的方法来获得完全的准确性.
# list of booleans to determine the correct predictions
correct_prediction = tf.equal(tf.argmax(pred, 1), np.array([6]*10))
print(correct_prediction.eval({x:adversarial}))
>> [True, True ... , True, True]
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print("Accuracy:", accuracy.eval({x: adversarial}))
>> Accuracy: 1.0我得到了1.0的精确性。这是什么意思,我的模型是100%的准确性?如果是这样的话,我一定是做错了什么。
发布于 2017-05-14 20:51:04
这有道理吗??如果您需要更多信息,请发表评论。
https://stackoverflow.com/questions/43968615
复制相似问题