OCR-D / ocrd_anybaseocr

DFKI Layout Detection for OCR-D
Apache License 2.0
48 stars 12 forks source link

Use SavedModel instead of HDF5 format, fix dewarping #89

Closed bertsky closed 2 years ago

bertsky commented 2 years ago

On Python 3.8, you get errors trying to load the existing HDF5 models for Tensorflow processors tiseg and layout-analysis.

However, Tensorflow offers a more stable alternative: SavedModel directories. I have converted the existing models an adapted the code to make them runnable again.

Now, how do we redistribute these? I have uploaded them as tarballs here and here. But really they should go to https://ocr-d-repo.scc.kit.edu/models/dfki as well.

As soon as we get https://github.com/OCR-D/core/pull/800 done, we should then be able to update the resource list in ocrd-tool.json, right?

Another dependency is in the processors using ocrolib.morph, i.e. nlbin and textline: https://github.com/OCR-D/ocropy/pull/2 – @kba, as soon as you have merged and published ocrd-fork-ocropy==1.4.0a4, this is ready to go.

bertsky commented 2 years ago

Now also depends on https://github.com/NVIDIA/pix2pixHD/pull/293, and contains various other fixes, mostly regarding dewarping.

Fixes #34, #35, #40, #60, #61, #72, #73, #77, #87, #88, and probably #42 (see below – with resize_mode=none).

With better upsampling/re-binarization, the quality of the dewarper has also improved a little. It is obviously not a good idea to downsample in the first place (which is the case with the default resize_mode=resize_and_crop). But one could always increase resize_width/resize_height, or use resize_mode=none to gain full size quality at the cost of higher memory and time demand.

Here are some examples based on the dfki-testdata test case (after binarization and cropping):

dewarped with default settings:

before after
dfki-crop-test dfki-dewarp-test-bin

dewarped with default settings but on GPU:

before after
dfki-crop-test dfki-dewarp-test-bin-gpu

dewarped with larger size (less resampling/interpolation):

before after
dfki-crop-test dfki-dewarp-test-bin-large

dewarped with original/full image size:

before after
dfki-crop-test dfki-dewarp-test-bin-full

dewarped on cropped but raw RGB (just to show that the models have not been trained on such data):

before after
dfki-crop-test dfki-dewarp-test-raw
bertsky commented 2 years ago

Now, how do we redistribute these? I have uploaded them as tarballs here and here. But really they should go to https://ocr-d-repo.scc.kit.edu/models/dfki as well.

Like I said, we still need to upload the new models, and update the resource URLs. (This is the reason the CI still fails.)

bertsky commented 2 years ago

Fixes #34, #35, #40, #60, #61, #72, #73, #77, #87, #88, and probably #42

BTW I forgot to link these (and my formulation is not covered by autolinking). Please close them.