From 7dff7784c5533ff569160b278c7ca6462c3603d4 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Tue, 21 Jul 2020 18:16:52 +0200 Subject: [PATCH 1/8] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20to=20Calamari?= =?UTF-8?q?=201.0.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0a426e0..53a18b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy -tensorflow-gpu == 1.15.* -calamari-ocr == 0.3.5 +tensorflow-gpu == 2.2.* +calamari-ocr == 1.0.* setuptools >= 41.0.0 # tensorboard depends on this, but why do we get an error at runtime? click ocrd >= 2.2.1 From 8ab57e44dc45bb3004200a10ed1cf467f44447af Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Tue, 21 Jul 2020 18:52:47 +0200 Subject: [PATCH 2/8] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20model=20downl?= =?UTF-8?q?oad=20for=20Calamari=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e65df22..61ca7f3 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ install: gt4histocr-calamari: mkdir gt4histocr-calamari cd gt4histocr-calamari && \ - wget https://qurator-data.de/calamari-models/GT4HistOCR/model.tar.xz && \ + wget https://qurator-data.de/calamari-models/GT4HistOCR/2019-12-11T11_10+0100/model.tar.xz && \ tar xfv model.tar.xz && \ rm model.tar.xz From 9ea50e25d17acbc19426c15860c7b37b194f0b67 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Tue, 21 Jul 2020 18:16:52 +0200 Subject: [PATCH 3/8] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20to=20Calamari?= =?UTF-8?q?=201.0.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0a426e0..53a18b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy -tensorflow-gpu == 1.15.* -calamari-ocr == 0.3.5 +tensorflow-gpu == 2.2.* +calamari-ocr == 1.0.* setuptools >= 41.0.0 # tensorboard depends on this, but why do we get an error at runtime? click ocrd >= 2.2.1 From 7584d0135ce6f3988909244a1a6f49fbadf314ad Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Tue, 21 Jul 2020 18:52:47 +0200 Subject: [PATCH 4/8] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20model=20downl?= =?UTF-8?q?oad=20for=20Calamari=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e65df22..61ca7f3 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ install: gt4histocr-calamari: mkdir gt4histocr-calamari cd gt4histocr-calamari && \ - wget https://qurator-data.de/calamari-models/GT4HistOCR/model.tar.xz && \ + wget https://qurator-data.de/calamari-models/GT4HistOCR/2019-12-11T11_10+0100/model.tar.xz && \ tar xfv model.tar.xz && \ rm model.tar.xz From 93190fae3b3d8b5b9a68b37f604c43c34979e5d4 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Wed, 22 Jul 2020 16:03:10 +0200 Subject: [PATCH 5/8] =?UTF-8?q?=E2=9A=A1=20Recognize=20more=20than=20one?= =?UTF-8?q?=20line=20at=20a=20time=20(Fixes=20gh#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ocrd_calamari/recognize.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ocrd_calamari/recognize.py b/ocrd_calamari/recognize.py index 8ae0a17..d040550 100644 --- a/ocrd_calamari/recognize.py +++ b/ocrd_calamari/recognize.py @@ -72,13 +72,16 @@ class CalamariRecognize(Processor): textlines = region.get_TextLine() log.info("About to recognize %i lines of region '%s'", len(textlines), region.id) - for (line_no, line) in enumerate(textlines): - log.debug("Recognizing line '%s' in region '%s'", line.id, region.id) + line_images_np = [] + for (line_no, line) in enumerate(textlines): line_image, line_coords = self.workspace.image_from_segment(line, region_image, region_xywh) line_image_np = np.array(line_image, dtype=np.uint8) + line_images_np.append(line_image_np) + raw_results_all = self.predictor.predict_raw(line_images_np, progress_bar=False) + + for line, raw_results in zip(textlines, raw_results_all): - raw_results = list(self.predictor.predict_raw([line_image_np], progress_bar=False))[0] for i, p in enumerate(raw_results): p.prediction.id = "fold_{}".format(i) From d9afb05cf32e75481ff090e3ffb7d30fd2cb7511 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Thu, 23 Jul 2020 12:44:15 +0200 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=90=9B=20Use=20TensorFlow=20>=3D=202.?= =?UTF-8?q?3.0rc2=20to=20fix=20retracing=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 53a18b0..f7ece9d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ numpy -tensorflow-gpu == 2.2.* +tensorflow >= 2.3.0rc2 calamari-ocr == 1.0.* setuptools >= 41.0.0 # tensorboard depends on this, but why do we get an error at runtime? click From 0a9dbd0c25b71b034918db36393e793660554777 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Thu, 23 Jul 2020 13:04:11 +0200 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=A7=B9=20Do=20not=20install=20numpy,?= =?UTF-8?q?=20let=20the=20TF=20dependency=20do=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f7ece9d..a1de85a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -numpy tensorflow >= 2.3.0rc2 calamari-ocr == 1.0.* setuptools >= 41.0.0 # tensorboard depends on this, but why do we get an error at runtime? From 0e59c2317a579d26ddc111a9d3b49d3eddcaa53e Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Wed, 25 Nov 2020 12:09:41 +0100 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=91=B7=F0=9F=8F=BE=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20Use=20gt4histocr-calamari1/=20as=20directory=20name?= =?UTF-8?q?=20for=20the=20Calmari=201=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 12 ++++++------ README.md | 8 ++++---- test/test_recognize.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 61ca7f3..00a8f69 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ help: @echo " Targets" @echo "" @echo " install Install ocrd_calamari" - @echo " gt4histocr-calamari Get GT4HistOCR Calamari model (from SBB)" + @echo " gt4histocr-calamari1 Get GT4HistOCR Calamari model (from SBB)" @echo " actevedef_718448162 Download example data" @echo " deps-test Install testing python deps via pip" @echo " repo/assets Clone OCR-D/assets to ./repo/assets" @@ -34,9 +34,9 @@ install: # Get GT4HistOCR Calamari model (from SBB) -gt4histocr-calamari: - mkdir gt4histocr-calamari - cd gt4histocr-calamari && \ +gt4histocr-calamari1: + mkdir -p gt4histocr-calamari1 + cd gt4histocr-calamari1 && \ wget https://qurator-data.de/calamari-models/GT4HistOCR/2019-12-11T11_10+0100/model.tar.xz && \ tar xfv model.tar.xz && \ rm model.tar.xz @@ -73,12 +73,12 @@ assets-clean: rm -rf test/assets # Run unit tests -test: test/assets gt4histocr-calamari +test: test/assets gt4histocr-calamari1 # declare -p HTTP_PROXY $(PYTHON) -m pytest --continue-on-collection-errors test $(PYTEST_ARGS) # Run unit tests and determine test coverage -coverage: test/assets gt4histocr-calamari +coverage: test/assets gt4histocr-calamari1 coverage erase make test PYTHON="coverage run" coverage report diff --git a/README.md b/README.md index e158b8d..9b111fb 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ pip install . Download models trained on GT4HistOCR data: ``` -make gt4histocr-calamari -ls gt4histocr-calamari +make gt4histocr-calamari1 +ls gt4histocr-calamari1 ``` ## Example Usage @@ -50,7 +50,7 @@ Before using `ocrd-calamari-recognize` get some example data and model, and prepare the document for OCR: ``` # Download model and example data -make gt4histocr-calamari +make gt4histocr-calamari1 make actevedef_718448162 # Create binarized images and line segmentation using other OCR-D projects @@ -62,7 +62,7 @@ ocrd-tesserocr-segment-line -I OCR-D-SEG-REGION -O OCR-D-SEG-LINE Finally recognize the text using ocrd_calamari and the downloaded model: ``` -ocrd-calamari-recognize -p '{ "checkpoint": "../gt4histocr-calamari/*.ckpt.json" }' -I OCR-D-SEG-LINE -O OCR-D-OCR-CALAMARI +ocrd-calamari-recognize -p '{ "checkpoint": "../gt4histocr-calamari1/*.ckpt.json" }' -I OCR-D-SEG-LINE -O OCR-D-OCR-CALAMARI ``` You may want to have a look at the [ocrd-tool.json](ocrd_calamari/ocrd-tool.json) descriptions diff --git a/test/test_recognize.py b/test/test_recognize.py index 54faf87..eee45d9 100644 --- a/test/test_recognize.py +++ b/test/test_recognize.py @@ -14,7 +14,7 @@ from .base import assets METS_KANT = assets.url_of('kant_aufklaerung_1784-page-region-line-word_glyph/data/mets.xml') WORKSPACE_DIR = '/tmp/test-ocrd-calamari' -CHECKPOINT = os.path.join(os.getcwd(), 'gt4histocr-calamari/*.ckpt.json') +CHECKPOINT = os.path.join(os.getcwd(), 'gt4histocr-calamari1/*.ckpt.json') # Because XML namespace versions are so much fun, we not only use one, we use TWO! NSMAP = { "pc": "http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" }