如何使用keras image_ocr示例预测OCR的结果? [英] How to predict the results for OCR using keras image_ocr example?

查看:262
本文介绍了如何使用keras image_ocr示例预测OCR的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Keras OCR示例演示了使用堆叠的CNN和RNN开发的非常简单的OCR系统.但是在训练后如何使用训练后的模型预测结果? 链接到image_ocr

Keras OCR example demonstrates a very simple OCR system developed using a stacked CNN and RNN. But after training how to predict results using the trained model? Link for image_ocr

推荐答案

使用model.fit()函数拟合模型后,即可:

Once you've fit your model using the model.fit() function:

model.fit(X_training_data,Y_training_data,...)

您可以使用model.evaluate()评估模型,如下所示:

you can evaluate your model using model.evaluate(), like so:

model.evaluate(X_test, y_test, verbose=0)

,如果要保存模型,则:

and if you want to save your model:

model.save('my_nn.hdf5')

请注意,将X和y数据分为训练和测试数据集的最简单方法是获取前N个观测值,并将其作为测试数据集,将其余的作为测试数据集.有时会为您拆分测试和培训集,例如

Note that the simplest way to split your X and y data into a training and test data set is just to obtain the first N observations, and let those be your testing data set, and let the remainder be the testing data set. Sometimes the testing and training set are split for you, as is the case with NIST's optical digit recognition data set:

testing_df = pd.read_csv('data/optdigits/optdigits.tes',header=None)
X_testing,  y_testing  = testing_df.loc[:,0:63],  testing_df.loc[:,64]

training_df = pd.read_csv('data/optdigits/optdigits.tra',header=None)
X_training, y_training = training_df.loc[:,0:63], training_df.loc[:,64]

此示例将测试和训练集分为(a)包含数字灰度图像的64个像素的64个元素矢量[:,0:63]和(b)包含该数字的1个元素矢量[:,64]图片代表.

This example splits the testing and training set into (a) a 64-element vector [:,0:63] containing the 64 pixels of the greyscale image of the digit, and (b) a 1-element vector [:,64] containing which digit the image represents.

这篇关于如何使用keras image_ocr示例预测OCR的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆