axcelerateai / urdu-handwriting-recognition-using-deep-learning

This repository implements several deep learning architectures for Urdu handwriting recognition.
MIT License
9 stars 5 forks source link

Default config file "CNN_RNN_CTC_BLS.json" not working during inference #4

Open fazeelbhatti opened 4 years ago

fazeelbhatti commented 4 years ago

InvalidArgumentError (see above for traceback): 0-th value returned by pyfunc_0 is int32, but expects int64 [[node model/PyFunc (defined at F:\Toys\Urdu OCR\Urdu-Handwriting-Recog nition-using-Deep-Learning-master\models\lm.py:150) ]]

I'm on windows and using a conda environment. Seems like some issue with tensorflow's datatypes.

Also the gui does not work if the config file is changed. I fixed this by editing the "loading_complete" method in run_gui.py.

I can run the other configurations and the only difference in the configs is the "decoder-type: Prefix_beam_search" which I think is somehow linked with how you are using the language model.

Could you please also guide to some resource on how the language model is being integrated at the output of the model in your code.

shehryar-malik commented 4 years ago

The code for the language model follows more or less this: https://towardsdatascience.com/word-beam-search-a-ctc-decoding-algorithm-b051d28f3d2e

The main difference is that the algorithm in this article was specifically designed for English where a 'space' indicates the end of word, whereas in Urdu we have no spaces. Since the scheme that I used for transcription differentiated between whether a character was at the start, middle or end of a word, I simply changed the 'space' condition to an 'ending character' condition.

For the datatype error you're encountering, make sure that you're using the same versions of the library as mentioned in the requirements.txt file. Otherwise, as far as this error is concerned, if you explicitly cast the variables (indices, values, shape) being returned at line 145 in models/lm.py to np.int64, I think the error should go away.