Bartzi / stn-ocr

Code for the paper STN-OCR: A single Neural Network for Text Detection and Text Recognition
https://arxiv.org/abs/1707.08831
GNU General Public License v3.0
499 stars 139 forks source link

Error in running eval_text_recognition.py #4

Closed vermaarjun7 closed 7 years ago

vermaarjun7 commented 7 years ago

Hi, I'm using the text recognition pretrained model downloaded from the website. I'm getting the following error in running this script. Any idea how to solve this?

python eval_text_recognition_model.py model-0002.params 10000 original_gt.txt model-symbol.json

Traceback (most recent call last):
  File "eval_text_recognition_model.py", line 97, in <module>
    reverse_char_map = {v: k for k, v in char_map.items()}
  File "eval_text_recognition_model.py", line 97, in <dictcomp>
    reverse_char_map = {v: k for k, v in char_map.items()}
TypeError: unhashable type: 'list'

Also, how many epochs I should set for the best results? I couldn't find it in the paper.

Thanks

Bartzi commented 7 years ago

Hi,

the problem is that you are using the symbol file model-symbol.json as char map. You should actually use this file.

The char map is used for mapping the output classes to the corresponding unicode.

Regarding the epoch question: If you are using the data provided by Jaderberg et al. you won't need more than 2 epochs, as the sheer amount of data is already enough the network stops to make notable progress.

I hope I could help =)

vermaarjun7 commented 7 years ago

Thankyou @Bartzi . It worked

pribadihcr commented 7 years ago

@Bartzi, @vermaarjun7,

How to execute eval_text_recognition_model.py ?

/stn-ocr/mxnet$ python eval_text_recognition_model.py model/model-0002.params 10000 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json

I got the following error: Stack trace returned 10 entries: [bt] (0) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(+0x12745f9) [0x7f88080bf5f9] [bt] (1) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(+0x126cefa) [0x7f88080b7efa] [bt] (2) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(MXSymbolCreateFromFile+0x4e) [0x7f8807c52fbe] [bt] (3) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c) [0x7f88491afadc] [bt] (4) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call+0x1fc) [0x7f88491af40c] [bt] (5) /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so(_ctypes_callproc+0x48e) [0x7f88493c66be] [bt] (6) /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so(+0x1606e) [0x7f88493c806e] [bt] (7) python(PyEval_EvalFrameEx+0x5d05) [0x559a35] [bt] (8) python(PyEval_EvalCodeEx+0x251) [0x574821] [bt] (9) python(PyEval_EvalFrameEx+0x6824) [0x55a554]

Traceback (most recent call last): File "eval_text_recognition_model.py", line 102, in model = get_model(args, data_shape, output_size) File "eval_text_recognition_model.py", line 24, in get_model symbol, arg_params, aux_params = mx.model.load_checkpoint(args.model_prefix, args.model_epoch) File "/usr/local/lib/python2.7/dist-packages/mxnet/model.py", line 394, in load_checkpoint symbol = sym.load('%s-symbol.json' % prefix) File "/usr/local/lib/python2.7/dist-packages/mxnet/symbol.py", line 1900, in load check_call(_LIB.MXSymbolCreateFromFile(c_str(fname), ctypes.byref(handle))) File "/usr/local/lib/python2.7/dist-packages/mxnet/base.py", line 129, in check_call raise MXNetError(py_str(_LIB.MXGetLastError())) mxnet.base.MXNetError: [21:12:14] src/io/local_filesys.cc:154: Check failed: allow_null LocalFileSystem: fail to open "model/model-0002.params-symbol.json"

Stack trace returned 10 entries: [bt] (0) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(+0x12745f9) [0x7f88080bf5f9] [bt] (1) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(+0x126cefa) [0x7f88080b7efa] [bt] (2) /usr/local/lib/python2.7/dist-packages/mxnet/libmxnet.so(MXSymbolCreateFromFile+0x4e) [0x7f8807c52fbe] [bt] (3) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c) [0x7f88491afadc] [bt] (4) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call+0x1fc) [0x7f88491af40c] [bt] (5) /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so(_ctypes_callproc+0x48e) [0x7f88493c66be] [bt] (6) /usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so(+0x1606e) [0x7f88493c806e] [bt] (7) python(PyEval_EvalFrameEx+0x5d05) [0x559a35] [bt] (8) python(PyEval_EvalCodeEx+0x251) [0x574821] [bt] (9) python(PyEval_EvalFrameEx+0x6824) [0x55a554]

Bartzi commented 7 years ago

You called the script with the wrong arguments. Instead of python eval_text_recognition_model.py model/model-0002.params 10000 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json

you should do it like this python eval_text_recognition_model.py model/model 0002 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json

You should give the prefix to the model path an the number of the epoch you want to evaluate. I know this is not intuitive, but this is the way Mxnet expects it and I did not want to change everything in this library ;)

pribadihcr commented 7 years ago

Thanks. I got the next error:

stn-ocr/mxnet$ python3.5 eval_text_recognition_model.py model/model 0002 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json [08:56:59] /home/deep307/SHARE/siiva/bibnumber_recognition/stn-ocr/incubator-mxnet/dmlc-core/include/dmlc/./logging.h:308: [08:56:59] src/core/op.cc:55: Check failed: op != nullptr Operator WarpCTC is not registered

Stack trace returned 10 entries: [bt] (0) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm2Op3GetERKSs+0x365) [0x7f1c05fb3025] [bt] (1) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(+0x3e989a2) [0x7f1c05fef9a2] [bt] (2) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4dmlc20JSONObjectReadHelper13ReadAllFieldsEPNS_10JSONReaderE+0xf3) [0x7f1c05ff50d3] [bt] (3) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(+0x3e966f3) [0x7f1c05fed6f3] [bt] (4) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZNSt17_Function_handlerIFN4nnvm5GraphES1_EPS2_E9_M_invokeERKSt9_AnydataOS1+0x109) [0x7f1c04a5d8b9] [bt] (5) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x2f7) [0x7f1c05fb6897] [bt] (6) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN5mxnet18LoadLegacyJSONPassEN4nnvm5GraphE+0x878) [0x7f1c04a4d0d8] [bt] (7) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZNSt17_Function_handlerIFN4nnvm5GraphES1_EPS2_E9_M_invokeERKSt9_AnydataOS1+0x109) [0x7f1c04a5d8b9] [bt] (8) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x2f7) [0x7f1c05fb6897] [bt] (9) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm9ApplyPassENS_5GraphERKSs+0x39f) [0x7f1c047fe20f]

Traceback (most recent call last): File "eval_text_recognition_model.py", line 102, in model = get_model(args, data_shape, output_size) File "eval_text_recognition_model.py", line 24, in get_model symbol, arg_params, aux_params = mx.model.load_checkpoint(args.model_prefix, args.model_epoch) File "/usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/model.py", line 394, in load_checkpoint symbol = sym.load('%s-symbol.json' % prefix) File "/usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/symbol/symbol.py", line 2494, in load check_call(_LIB.MXSymbolCreateFromFile(c_str(fname), ctypes.byref(handle))) File "/usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/base.py", line 146, in check_call raise MXNetError(py_str(_LIB.MXGetLastError())) mxnet.base.MXNetError: Failed loading Op warpctc0 of type WarpCTC: [08:56:59] src/core/op.cc:55: Check failed: op != nullptr Operator WarpCTC is not registered

Stack trace returned 10 entries: [bt] (0) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm2Op3GetERKSs+0x365) [0x7f1c05fb3025] [bt] (1) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(+0x3e989a2) [0x7f1c05fef9a2] [bt] (2) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4dmlc20JSONObjectReadHelper13ReadAllFieldsEPNS_10JSONReaderE+0xf3) [0x7f1c05ff50d3] [bt] (3) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(+0x3e966f3) [0x7f1c05fed6f3] [bt] (4) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZNSt17_Function_handlerIFN4nnvm5GraphES1_EPS2_E9_M_invokeERKSt9_AnydataOS1+0x109) [0x7f1c04a5d8b9] [bt] (5) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x2f7) [0x7f1c05fb6897] [bt] (6) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN5mxnet18LoadLegacyJSONPassEN4nnvm5GraphE+0x878) [0x7f1c04a4d0d8] [bt] (7) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZNSt17_Function_handlerIFN4nnvm5GraphES1_EPS2_E9_M_invokeERKSt9_AnydataOS1+0x109) [0x7f1c04a5d8b9] [bt] (8) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorISsSaISsEE+0x2f7) [0x7f1c05fb6897] [bt] (9) /usr/local/lib/python3.5/site-packages/mxnet-0.12.0-py3.5.egg/mxnet/libmxnet.so(_ZN4nnvm9ApplyPassENS_5GraphERKSs+0x39f) [0x7f1c047fe20f]

On Tue, Oct 24, 2017 at 9:37 PM, Christian Bartz notifications@github.com wrote:

You called the script with the wrong arguments. Instead of python eval_text_recognition_model.py model/model-0002.params 10000 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json

you should do it like this python eval_text_recognition_model.py model/model 0002 ../datasets/text_recognition/textrec.csv ../datasets/text_recognition/ctc_char_map.json

You should give the prefix to the model path an the number of the epoch you want to evaluate, so know this is not intuitive, but this is the way Mxnet expects it and I did not want to change everything in this library ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Bartzi/stn-ocr/issues/4#issuecomment-338992634, or mute the thread https://github.com/notifications/unsubscribe-auth/AMdn_pS9Hfrt8Nu8deAvCETeR8CoGjDMks5svegbgaJpZM4PldZt .

Bartzi commented 7 years ago

okay,

please have a look at this line from your traceback: Check failed: op != nullptr Operator WarpCTC is not registered It tells us, that you did not add the warpctc plugin to your installation of mxnet, as required in step 8 of the installation instructions. You are furthermore using a version of mxnet that is too new. All of the code is only tested to run with mxnet version 0.9.3, whereas it seems that you are using version 0.12.0. Please make sure to recompile mxnet with the warpctc plugin enabled and using the correct version.