我已经训练了卷积神经网络来识别手写数字。我已经完成了算法的训练部分,并且在测试集上也获得了99%的准确性。我已经使用了MNIST数据集。使用测试集时,下雨算法可以给出正确的预测。但是,当我使用训练和测试数据中未包含的图像时,仅给出8作为预测。帮助我解决这个问题。
手写数字:
cnn代码:
layer_fc1 = new_fc_layer(input=layer_flat,
num_inputs=num_features,
num_outputs=fc_size,
use_relu=True)
layer_fc2 = new_fc_layer(input=layer_fc1,
num_inputs=fc_size,
num_outputs=num_classes,
use_relu=False)
y_pred = tf.nn.softmax(layer_fc2)
y_pred_cls = tf.argmax(y_pred, axis=1)
Accuracy on Test-Set: 99.1% (9905 / 10000)
Example errors:
saver.restore(session, "model/conv_net.ckpt")
test_image_new = digits.reshape(len(boxes),784)
test_image_new = img_as_float(test_image_new)
test_image_digit = 1. - test_image_new
# Create a feed-dict with these images and labels.
# Calculate the predicted class using TensorFlow.
test_results = session.run(y_pred_cls, feed_dict = {x: test_image_digit})
print(test_results)
INFO:tensorflow:Restoring parameters from model/conv_net.ckpt
[8 8]