在CNN中获得相同的手写数字识别输出

2024-05-20 01:07:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我训练了一个卷积神经网络来识别手写数字。我已经完成了算法的训练部分,并且在测试集上获得了99%的准确率。我使用了MNIST数据集,训练算法在使用测试集时给出了正确的预测。但是当我使用了一个没有包含在训练和测试数据中的图像时,只给出8作为预测。帮我把这个修好

手写数字:

enter image description here

cnn代码:

enter image description here

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]

Tags: testimage算法layernewinputsize数字