如何在tensorflow MLP Mnist示例

时间:2018-05-18 13:38:31

标签: python tensorflow

我有Tensorflow MLP Mnist example based个简单的分类器,它在RGB 32x32图像上分类面和no_face。

代码运作良好并计算分类准确度

Epoch: 0001 cost = 6.539309704
Epoch: 0002 cost = 0.868323514
Epoch: 0003 cost = 0.265693334
Optimization Finished!
Accuracy network: 0.8974359

准确度由以下代码计算:

correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
#Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print("Accuracy network:", accuracy.eval({x: data.Images_test, y: data.Labels_test}))

如何在此模型中使用自己的图像运行预测?

我试过这段代码:

    image_with_no_face_1 = cv2.imread('a.jpg').reshape(1,3072)
    image_with_no_face_2 = cv2.imread('b.jpg').reshape(1,3072)
    image_with_face = cv2.imread('c.jpg').reshape(1,3072)

    print("Face :", accuracy.eval({x: image_with_no_face_1, y: data.Labels_test}))
    print("Face :", accuracy.eval({x: image_with_no_face_2, y: data.Labels_test}))
    print("Face :", accuracy.eval({x: image_with_face, y: data.Labels_test}))

并获得不正确的值

Epoch: 0002 cost = 1087.248228555
Epoch: 0003 cost = 837.800127911
Epoch: 0004 cost = 39.879899548
Epoch: 0005 cost = 461.961817526
Optimization Finished!
Accuracy network: 0.8974359
Face : 0.8974359
Face : 0.8974359
Face : 0.8974359

我认为我应该使用 tf.matmul()或类似的函数来代替 tf.reduce_mean(),但我无法找到任何可以使用的解决方案这个项目结构。

0 个答案:

没有答案