mittagessen / kraken

OCR engine for all the languages
http://kraken.re
Apache License 2.0
720 stars 130 forks source link

Error while using clstm models that I trained and test it ! #67

Closed Hadi58 closed 6 years ago

Hadi58 commented 6 years ago

Hi ! when I use default clstm models like arabic-beirut-200.clstm model, it's ok and convert successfully: user@user ~/Desktop/mags $ kraken -i images/tt1.jpg image.txt binarize segment ocr -m arabic-beirut- 200.clstm Loading RNN default ✓ Binarizing ✓ Segmenting ✓ Processing ✓ Writing recognition results for /tmp/tmpq1EMeq ✓ but when I use any clstm models that I trained and tested them I get: user@user ~/Desktop/mags $ kraken -i images/tt1.jpg image.txt binarize segment ocr -m persian-keyhan-5000.clstm Loading RNN default ✓ Binarizing ✓ Segmenting ✓ Traceback (most recent call last): File "/usr/local/bin/kraken", line 10, in sys.exit(cli()) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1093, in invoke return _process_result(rv) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1031, in _process_result ctx.params) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke return callback(args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/kraken/kraken.py", line 167, in process_pipeline task(base_image=base_image, input=input, output=output) File "/usr/local/lib/python2.7/dist-packages/kraken/kraken.py", line 125, in recognizer for pred in it: File "/usr/local/lib/python2.7/dist-packages/kraken/rpred.py", line 211, in mm_rpred pred = nets[script].predictString(line) File "/usr/local/lib/python2.7/dist-packages/kraken/lib/models.py", line 88, in predictString line = line.reshape(-1, self.rnn.ninput(), 1) ValueError: can only specify one unknown dimension


I use kraken version 0.9.6 : user@user ~/Desktop/mags $ kraken --version kraken, version 0.9.6.dev8 and compile separate-derivs branch to train my clstm model.

mittagessen commented 6 years ago

Could you make the model file available to me, so I can have a look?

Hadi58 commented 6 years ago

yes! of course! I sent it to your email.

Hadi58 commented 6 years ago

Hi mittagessen! thanks for your attention!

On Mon, Oct 23, 2017 at 5:08 PM, mittagessen notifications@github.com wrote:

Could you make the model file available to me, so I can have a look?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mittagessen/kraken/issues/67#issuecomment-338661682, or mute the thread https://github.com/notifications/unsubscribe-auth/AP-D4dtYLzVGOIEbHN2wIbJPlokFYWZfks5svJbygaJpZM4QB_70 .

mittagessen commented 6 years ago

Sorry, I can't find it. Could you resent it or put it somewhere else? My mail server drops mail over a certain size so it's certainly possible it was lost somewhere.

Hadi58 commented 6 years ago

@mittagessen Hi mittagessen! I sent it to your email again and shared this link too. https://drive.google.com/open?id=0B4rF4dafhi1gSVlQazcySzRSYXc thanks!

ghost commented 6 years ago

@Hadi58 What settings did you use to train clstm? How did you create the training data, did you scan pages then transcribed them? or did you generate artificially using a font by Ketos?

Hadi58 commented 6 years ago

@christophered I scanned old persian newspapers and transcribed and trained and tested them.

Hadi58 commented 6 years ago

@mittagessen I sent it to your email again and shared this link too. https://drive.google.com/open?id=0B4rF4dafhi1gSVlQazcySzRSYXc thanks!

jbaiter commented 6 years ago

I'm getting the same error with the fraktur.clstm model, i.e. not self-trained.

◆ kraken -i default.jpg default.hocr binarize segment ocr -h -m ~/.config/kraken/fraktur.clstm --disable-autoconversion
Loading RNN default     ✓
Binarizing      ✓
Segmenting      ✓
Traceback (most recent call last):
  File "/home/jojo/.envs/mocri-fk52DBAN/bin/kraken", line 11, in <module>
    sys.exit(cli())
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/click/core.py", line 1093, in invoke
    return _process_result(rv)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/click/core.py", line 1031, in _process_result
    **ctx.params)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/kraken/kraken.py", line 169, in process_pipeline
    task(base_image=base_image, input=input, output=output)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/kraken/kraken.py", line 127, in recognizer
    for pred in it:
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/kraken/rpred.py", line 210, in mm_rpred
    pred = nets[script].predictString(line)
  File "/home/jojo/.envs/mocri-fk52DBAN/lib/python3.6/site-packages/kraken/lib/models.py", line 93, in predictString
    line = line.reshape(-1, self.rnn.ninput(), 1)
ValueError: can only specify one unknown dimension
mittagessen commented 6 years ago

The issue stems from the clstm version. CLSTM uses a net layer type registry and resolves those during deserialization with the kind and name field (separate_derivs branch) or kind field only (master). Crucially, the layer identifiers have changed so master models can't be loaded with separate_derivs and vice versa and trying to do so has always caused an assertion for me. In your cases the input dimensionality is misparsed (weird because those fields haven't changed) as -1 causing the reshape with multiple unknown dimensions (-1, -1, 1). But the models are unmistakenly serialized using master clstm (missing name field).

Because the python bindings have been broken on master for a long time kraken has to use the separate_derivs version. I've been working on porting the backend to pytorch (although I haven't had much time for it lately) which will resolve these issues. It is only missing small parts such as the OpenML serialization so it shouldn't be much longer.