ocrd_anybaseocr icon indicating copy to clipboard operation
ocrd_anybaseocr copied to clipboard

Issue with de-warp - strange result

Open stefanCCS opened this issue 5 years ago • 22 comments
trafficstars

Hi Martin, we met shortly in Bonn. You have explained the de-warping which was very interesting for me. I have tried out a bit - and after some environment issues, I could run it. Unfortunately, the results (visible as image in OCR-D-IMG-DEWARP) looks very strange. Maybe I have used wrong parameters. I have used the model which is decribed in anybaseocr/models/readme.md: https://cloud.dfki.de/owncloud/index.php/s/3zKza5sRfQB3ygy I have used the following parameter sets: { "gpu_id":0, "pix2pixHD":"/home/stefan/ocrd_all/pix2pixHD", "model_name":"/home/stefan/ocrd_all/pix2pixHD/models/" } You can download the image examples here: ftp://ftp.ccs-gmbh.net (directory example1) User: OCRDExamples Password: OcRd%123!

stefanCCS avatar Feb 14 '20 14:02 stefanCCS

@stefanCCS that ftp server seems to be down. And it would be way easier if you just pasted the images here. Github then takes care of hosting them and you can immediately see them when browsing the issue.

bertsky avatar Feb 17 '20 11:02 bertsky

@stefanCCS that ftp server seems to be down. And it would be way easier if you just pasted the images here. Github then takes care of hosting them and you can immediately see them when browsing the issue.

I just have tried the FTP-access - and it has worked fine: wget --user=OCRDExamples --password='OcRd%123!' ftp://ftp.ccs-gmbh.net/example1/* --> Please try once more.

stefanCCS avatar Feb 17 '20 12:02 stefanCCS

--> Please try once more.

Working now, though only via wget, not FileZilla for some reason. Unless there is a privacy problem (looks like dutch newspaper?), I'd also appreciate uploads to GitHub.

kba avatar Feb 17 '20 12:02 kba

Ok, understood ;-) Here you can find attached the cropped image, which was taken as input to the dewarp. (I could not load the source image here, as it is too big). OCR-D-IMG-CROP-1

stefanCCS avatar Feb 17 '20 13:02 stefanCCS

Any update from somebody possible?

stefanCCS avatar Apr 14 '20 08:04 stefanCCS

Hard to say but I think #89 should fix or at least improve the issue. @stefanCCS feel free to reopen if you still encounter strange results with the newest release.

kba avatar Mar 20 '22 16:03 kba

Hi @kba , just have tried out (with update done via ocrd_all at 22.03.2022. I still get strange results (Image are very "blurry"). See e.g. this excerpt: image

I cannot re-open this issue: Will you do it? Should I create a new one?

stefanCCS avatar Mar 24 '22 07:03 stefanCCS

@stefanCCS as I explained here, you have to set a different resize_mode and resize_width for better quality (resolution), esp. with such large images. Also see improved help text.

bertsky avatar Mar 24 '22 11:03 bertsky

btw: I get this warning here - relevant ?

/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/torchvision/transforms/transforms.py:288: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
  "Argument interpolation should be of type InterpolationMode instead of int. "

stefanCCS avatar Mar 24 '22 13:03 stefanCCS

Tried out with

  • resize_mode none ==> Result: One example works better, the other one gets "out-of-memory" with more than 8GB RAM to try to allocate

  • resize_mode resize_and_crop (default) and resize_width 2048 (instead of default 1024)

  • ==> Result: Both examples are still very blurred

  • resize_mode resize_and_crop (default) and resize_width 4096 (instead of default 1024) ==> Result: One example works better, the other one gets "out-of-memory" with more than 8GB RAM to try to allocate

All done on full page level. Next try will be on region level ...

stefanCCS avatar Mar 24 '22 14:03 stefanCCS

I have tried out on region level (-P operation_level region) Then, I got the following exception (looking in the output folder, the just 1 region-dewarped-image was created, and this filename does not have any substructure - expected would be something linke *_TR-1, which I get e.g. when using ocrd-cis-ocropy-binarize.)

  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/bin/ocrd-anybaseocr-dewarp", line 8, in <module>
    sys.exit(cli())
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_dewarp.py", line 210, in cli
    return ocrd_cli_wrap_processor(OcrdAnybaseocrDewarper, *args, **kwargs)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd/decorators/__init__.py", line 88, in ocrd_cli_wrap_processor
    run_processor(processorClass, ocrd_tool, mets, workspace=workspace, **kwargs)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd/processor/helpers.py", line 88, in run_processor
    processor.process()
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_dewarp.py", line 169, in process
    prepare_data(self.opt, region_image), region, region_xywh, region_image.size, input_file)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd_anybaseocr/cli/ocrd_anybaseocr_dewarp.py", line 202, in _process_segment
    file_grp=self.output_file_grp,
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd/workspace.py", line 983, in save_image_file
    force=force)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd/workspace.py", line 365, in add_file
    ret = self.mets.add_file(file_grp, **kwargs)
  File "/home/ocrdadmin/ocrd_all/venv/sub-venv/headless-tf2/lib/python3.6/site-packages/ocrd_models/ocrd_mets.py", line 307, in add_file
    raise Exception("File with ID='%s' already exists" % ID)

stefanCCS avatar Mar 24 '22 15:03 stefanCCS

btw: I get this warning here - relevant ?

no, not relevant. (string vs int mapping of interpolation types does work.)

bertsky avatar Mar 24 '22 22:03 bertsky

  • Result: One example works better, the other one gets "out-of-memory" with more than 8GB RAM to try to allocate

Yes, it's memory-intensive for sure. That's by design, unfortunately. And it is a huge page.

Out of curiosity: have you tried on GPU as well?

bertsky avatar Mar 24 '22 22:03 bertsky

raise Exception("File with ID='%s' already exists" % ID)

thanks for the report – can you please try again with newest #91?

bertsky avatar Mar 24 '22 22:03 bertsky

  • Result: One example works better, the other one gets "out-of-memory" with more than 8GB RAM to try to allocate

Yes, it's memory-intensive for sure. That's by design, unfortunately. And it is a huge page.

Out of curiosity: have you tried on GPU as well?

No GPU available - work on getting one ...

For us this is not a huge page, it is a normal one - we sometimes get A1 newspapers with 600dpi - this is huge ;-)

stefanCCS avatar Mar 25 '22 07:03 stefanCCS

For us this is not a huge page, it is a normal one - we sometimes get A1 newspapers with 600dpi - this is huge ;-)

I see. I would say this simply is not possible at the moment with our architecture – unless you invest insane amounts of RAM.

bertsky avatar Mar 25 '22 08:03 bertsky

Maybe it works ok (in the meaning of RAM) on region level - I will try out ...

stefanCCS avatar Mar 25 '22 09:03 stefanCCS

Have tried out on Region-Level. Works ok with newest version 1.8. "ok" means

  • no issue with amount of RAM
  • no issue with blurred results
  • and some dewarping done ==> in general ok (but very slow on CPU).

It is ok for me to close this issue now (shall I do this?)

stefanCCS avatar Mar 28 '22 08:03 stefanCCS

Hi again, last (for now) comment from my side. I have tried out dewarping of a pretty strong warped region like this example here: image

Unfortunately, the result is not better (somehow worse) - see here: image

I would guess that the training has not seen this kind of strong warped examples. Maybe something to be improved?

Anyway, issue can be closed as no software bug is open.

stefanCCS avatar Mar 28 '22 08:03 stefanCCS

I would guess that the training has not seen this kind of strong warped examples. Maybe something to be improved?

Yes, that's exactly what I would assume. Unfortunately, the developers never documented what they used for training.

I guess we'll just have to write/wrap parameteric dewarpers...

bertsky avatar Mar 28 '22 11:03 bertsky

This brings me back to the idea, that ocrd-kraken-segment should learn "Regions-level". And with this lines, the dewarping should work ok. What do you think?

stefanCCS avatar Mar 28 '22 11:03 stefanCCS

This brings me back to the idea, that ocrd-kraken-segment should learn "Regions-level". And with this lines, the dewarping should work ok. What do you think?

You mean the line-level dewarping? Yes, I guess it would be better, but for extreme cases like this, the Ocropy dewarper currently is not working well – it only follows a certain amount of slope. (You'll probably have to set -P smoothness 0.1 or so.) In the future, it will directly follow the annotated polygon (or even baseline), instead of detecting the centerline via the old lineest mechanism.

But to get good textlines, even in the presence of high line warp, for print you can also use ocrd-cis-ocropy-segment on region level.

bertsky avatar Mar 28 '22 11:03 bertsky