python - MNIST手写数字分类器的预测

标签 python tensorflow keras mnist handwriting-recognition

我是深度学习的新手,正在使用 Keras 来学习它。我按照此 link 的说明进行操作使用 MNIST 数据集构建手写数字识别分类器。它在查看可比较的评估结果方面效果很好。我使用 tensorflow 作为 Keras 的后端。

现在我想读取一个带有手写数字的图像文件,并使用相同的模型预测它的数字。我认为图像需要首先转换为 28x28 尺寸和 255 深度?我不确定我的理解是否正确。如果是这样,我如何在 Python 中进行这种转换?如果我的理解不正确,需要什么样的改造?

提前致谢!

最佳答案

据我所知,您需要将其转换为 28x28 灰度图像才能在 Python 中使用它。这与用于训练 MNIST 的图像具有相同的形状和方案,并且张量都需要 784 (28 * 28) 大小的项目,每个项目的张量值都在 0-255 之间作为输入。

要调整图像大小,您可以使用 PIL 或 Pillow。参见 this SO postthis page in the Pillow docs (在前面提到的帖子中由 Wtower 链接,复制到这里是为了方便调整大小和保持纵横比,如果这是你想要做的。

喂!

干杯,

-马舒

关于python - MNIST手写数字分类器的预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45552856/

相关文章:

javascript - 检查输入 : expected dense_Dense1_input to have x dimension(s). 时出错,但得到形状为 y、z 的数组

python - TensorBoard --logdir ="path/to/log"(无法分配给运算符(operator))

python - 检查模型输入时出错 : the list of Numpy arrays that you are passing to your model is not the size the model expected

python - tensorflow 错误 : 'FileWriter' method

tensorflow - keras 模型中的平均权重

python - 在神经网络中准备训练和验证数据时出错

Python super 方法和调用替代方法

python - Tensorflow 初始化给出所有 1

python大文件解析

python - Gdal_rasterize nodata_value 不起作用