How to predict the results for OCR using keras ima

2019-07-11 18:40发布

问题:

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

回答1:

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

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

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')

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]

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.