Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calamari2 #118

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bf755a3
adapt to ocrd>=3.0
bertsky Sep 13, 2024
1edd5e7
make test: no assumption on OCRD resource location
bertsky Sep 15, 2024
3333cab
tests: adapt to v3, overhaul and add caching+threading modes
bertsky Sep 15, 2024
7aae9bc
require ocrd 3.0 and calamari-ocr 1.0.7
bertsky Sep 16, 2024
9611e2c
aggregate all lines instead of per region to better utilise batched p…
bertsky Sep 17, 2024
fb2a680
run prediction in bg thread (shared across pages to interleave CPU/GPU)
bertsky Sep 18, 2024
b9b0e13
let GPU memory grow by demand (instead of exclusive reservation)
bertsky Sep 18, 2024
46c2ef6
no more need for model fixup
bertsky Sep 18, 2024
e68ce5f
CI: increase RAM
bertsky Sep 18, 2024
4904a00
:fire: adapt to (and require) Calamari 2…
bertsky Sep 23, 2024
f7a870e
wait for executor to fully initialize (so we get input_channels)
bertsky Sep 26, 2024
1c13622
convert images to input_channels (required TensorShape)
bertsky Sep 26, 2024
26ba7f5
voter cannot be parallel; shmem is faster
bertsky Sep 26, 2024
e99daa4
test configs: test metsserver independent of pageparallel
bertsky Sep 26, 2024
27dc858
test with pytest-isolate so TF memory can be freed between tests
bertsky Sep 26, 2024
55c175c
expose device parameter, default to GPU
bertsky Sep 27, 2024
1a41330
:package: 2.0.0
bertsky Sep 27, 2024
37ff61e
add C2 models
bertsky Sep 27, 2024
260f184
use C2 deep3_fraktur19 model for testing
bertsky Sep 27, 2024
92cd36d
update models (5→6 HDF5→SavedModel)
bertsky Sep 27, 2024
c24d99c
update requirements (Calamari 2.3, remove implied TF)
bertsky Oct 1, 2024
25ab12b
update models (2.1→2.2 for Py3.11 `re` syntax)
bertsky Oct 1, 2024
0e35701
:fire: change license from Apache 2 to GPL 3
bertsky Oct 2, 2024
25e3560
switch from ThreadPoolExecutor to custom mp.Process bg task
bertsky Oct 9, 2024
da60d42
pass only line IDs instead of full TextLine objects
bertsky Oct 9, 2024
bb6321b
fix error handling and IPC with page workers…
bertsky Oct 18, 2024
3bb6cf4
use tf.data generator for `model.predict_on_batch` instead of tfaip's
bertsky Oct 18, 2024
f1c54d0
reduce base batch size -- too large for long lines
bertsky Oct 18, 2024
d054512
Merge branch 'master' into calamari2
bertsky Oct 18, 2024
5dafcfe
CI: test on smaller model
bertsky Oct 18, 2024
816562a
ocrd-tool.json: fix 2.2 model URLs (zip→tar.gz)
bertsky Oct 19, 2024
8e37d0d
CI: wait longer for test without output
bertsky Oct 19, 2024
1fb24af
Makefile: export MODEL variable
bertsky Oct 19, 2024
5545337
ocrd-tool.json: remove model default
bertsky Oct 19, 2024
4d46d49
disallow TF 2.12.0
bertsky Oct 19, 2024
5af55e3
robust shutdown
bertsky Oct 21, 2024
9276c8b
configure infinite dataset/pipeline via queue during setup, run one t…
bertsky Oct 22, 2024
03b69ec
line task threads: catch and raise when joining
bertsky Oct 30, 2024
fdb5ef4
cannot do bucket batching in this mode (occasionally stalls the pipel…
bertsky Oct 30, 2024
384f107
don't confuse received result with expected result
bertsky Oct 30, 2024
fcb40c1
fill up batches as long as any workers are receiving results
bertsky Oct 30, 2024
05b77c7
fix termination/interruption
bertsky Oct 30, 2024
d1c74fc
require ocrd 3.0.0b6 (mp)
bertsky Oct 30, 2024
2dfba15
Merge branch 'calamari2-subprocess' into calamari2
bertsky Oct 31, 2024
f97eb97
replace atexit with weakref, also add destructor
bertsky Nov 12, 2024
fdf452e
fix word/glyph level
bertsky Nov 12, 2024
a3142b8
test: proper shutdown w/ no side effects
bertsky Nov 12, 2024
c721161
test: no need for fixture as dict
bertsky Nov 12, 2024
594b9b7
test: default to supported model
bertsky Nov 12, 2024
a5f0df5
test: no need for --isolate anymore
bertsky Nov 12, 2024
175583b
require ocrd 3.0.0b7 (sub logging)
bertsky Nov 12, 2024
c00969f
install dev before normal requirements to avoid typing-extensions con…
bertsky Nov 12, 2024
298cf9a
require calamari-ocr 2.3.1 (s11n of results via queue)
bertsky Nov 12, 2024
d842416
coverage: try to include subprocess results
bertsky Nov 13, 2024
e9c12c8
CI: store coverage results
bertsky Nov 13, 2024
9a749b0
CI: fix indentation
bertsky Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.1
orbs:
codecov: codecov/codecov@3.3.0
codecov: codecov/codecov@5.0.3

jobs:
test:
Expand All @@ -21,13 +21,21 @@ jobs:
paths:
- "~/.cache/pip"
- run: pip3 install --upgrade pip
- run: make install deps-test-ubuntu PIP_INSTALL="pip3 install"
- run: make coverage
- codecov/upload
- run:
name: install dependencies and package
command: make deps-test-ubuntu install PIP_INSTALL="pip3 install"
- save_cache:
key: v01-pydeps-<< parameters.python-image >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}
paths:
- "~/.cache/pip"
- run:
name: run regression test and coverage test
command: make coverage
no_output_timeout: 30m
- codecov/upload
- store_artifacts:
path: htmlcov
resource_class: large

workflows:
build:
Expand Down
877 changes: 676 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ export # export variables to subshells
PIP_INSTALL = pip3 install
GIT_CLONE = git clone
PYTHON = python3
PYTEST_ARGS = -W 'ignore::DeprecationWarning' -W 'ignore::FutureWarning'
MODEL = qurator-gt4histocr-1.0
PYTEST_ARGS = -W 'ignore::DeprecationWarning' -W 'ignore::FutureWarning' -vv
# not usable with Calamari 2 ATM - see Calamari#362
#MODEL = qurator-gt4histocr-1.0 # cannot be migrated to Calamari 2
#MODEL = deep3_fraktur19 # too large for CI
MODEL = fraktur_19th_century
export MODEL # needed for pytest model selection
EXAMPLE = actevedef_718448162.first-page+binarization+segmentation

# BEGIN-EVAL makefile-parser --make-help Makefile
Expand Down Expand Up @@ -82,12 +86,13 @@ assets-clean:
# Run unit tests
test: test/assets $(MODEL)
# declare -p HTTP_PROXY
$(PYTHON) -m pytest --continue-on-collection-errors test $(PYTEST_ARGS)
$(PYTHON) -m pytest --continue-on-collection-errors --durations=0 test $(PYTEST_ARGS)

# Run unit tests and determine test coverage
coverage: test/assets $(MODEL)
coverage erase
make test PYTHON="coverage run"
coverage combine
coverage report
coverage html

Expand Down
5 changes: 0 additions & 5 deletions ocrd_calamari/config.py

This file was deleted.

41 changes: 0 additions & 41 deletions ocrd_calamari/fix_calamari1_model.py

This file was deleted.

172 changes: 115 additions & 57 deletions ocrd_calamari/ocrd-tool.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"git_url": "https://github.com/OCR-D/ocrd_calamari",
"version": "1.0.6",
"version": "2.0.0",
"tools": {
"ocrd-calamari-recognize": {
"executable": "ocrd-calamari-recognize",
Expand All @@ -11,24 +11,28 @@
"recognition/text-recognition"
],
"description": "Recognize lines with Calamari",
"input_file_grp": [
"OCR-D-SEG-LINE"
],
"output_file_grp": [
"OCR-D-OCR-CALAMARI"
],
"input_file_grp_cardinality": 1,
"output_file_grp_cardinality": 1,
"parameters": {
"device": {
"description": "Select computing device for Tensorflow (-1 for CPU, 0 for first CUDA GPU etc.). Downgraded to CPU if not available.",
"type": "number",
"format": "integer",
"default": 0
},
"checkpoint_dir": {
"description": "The directory containing calamari model files (*.ckpt.json). Uses all checkpoints in that directory",
"description": "The directory (name or path) containing Calamari model files (*.ckpt.json). Will use all checkpoints in that directory.",
"type": "string",
"format": "uri",
"content-type": "text/directory",
"cacheable": true,
"default": "qurator-gt4histocr-1.0"
"required": true
},
"voter": {
"description": "The voting algorithm to use",
"type": "string", "default": "confidence_voter_default_ctc"
"type": "string",
"default": "confidence_voter_default_ctc",
"enum": ["confidence_voter_default_ctc", "sequence_voter"]
},
"textequiv_level": {
"type": "string",
Expand All @@ -50,107 +54,161 @@
"name": "qurator-gt4histocr-1.0",
"description": "Calamari model trained with GT4HistOCR",
"size": 90275264,
"version_range": ">= 1.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.1-pre1/c1_fraktur19-1.tar.gz",
"type": "archive",
"name": "zpd-fraktur19",
"description": "Model trained on 19th century german fraktur",
"path_in_archive": "c1_fraktur19-1",
"size": 86009886,
"version_range": ">= 1.0.0"
"version_range": ">= 1.0.0, < 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.1-pre1/c1_latin-script-hist-3.tar.gz",
"type": "archive",
"name": "zpd-latin-script-hist-3",
"path_in_archive": "c1_latin-script-hist-3",
"description": "Model trained on historical latin-script texts",
"size": 88416863,
"version_range": ">= 1.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/antiqua_historical.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/antiqua_historical.tar.gz",
"type": "archive",
"name": "antiqua_historical",
"path_in_archive": "antiqua_historical",
"description": "Antiqua parts of GT4HistOCR from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale, NFC)",
"size": 89615540,
"version_range": ">= 1.0.0"
"size": 30633860,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/antiqua_historical_ligs.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/antiqua_historical_ligs.tar.gz",
"type": "archive",
"name": "antiqua_historical_ligs",
"path_in_archive": "antiqua_historical_ligs",
"description": "Antiqua parts of GT4HistOCR with enriched ligatures from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale, NFC)",
"size": 87540762,
"version_range": ">= 1.0.0"
"size": 30368081,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/fraktur_19th_century.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/fraktur_19th_century.tar.gz",
"type": "archive",
"name": "fraktur_19th_century",
"path_in_archive": "fraktur_19th_century",
"description": "Fraktur 19th century parts of GT4HistOCR mixed with Fraktur data from Archiscribe and jze from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale and nlbin, NFC)",
"size": 83895140,
"version_range": ">= 1.0.0"
"size": 30018408,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/fraktur_historical.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/fraktur_historical.tar.gz",
"type": "archive",
"name": "fraktur_historical",
"path_in_archive": "fraktur_historical",
"description": "Fraktur parts of GT4HistOCR from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale, NFC)",
"size": 87807639,
"version_range": ">= 1.0.0"
"size": 30232783,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/fraktur_historical_ligs.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/fraktur_historical_ligs.tar.gz",
"type": "archive",
"name": "fraktur_historical_ligs",
"path_in_archive": "fraktur_historical_ligs",
"description": "Fraktur parts of GT4HistOCR with enriched ligatures from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale, NFC)",
"size": 88039551,
"version_range": ">= 1.0.0"
"size": 30622320,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/gt4histocr.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/gt4histocr.tar.gz",
"type": "archive",
"name": "gt4histocr",
"path_in_archive": "gt4histocr",
"description": "GT4HistOCR from Calamari-OCR/calamari_models (5-fold ensemble, normalized grayscale, NFC)",
"size": 90107851,
"version_range": ">= 1.0.0"
"size": 31159925,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/historical_french.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/historical_french.tar.gz",
"type": "archive",
"name": "historical_french",
"path_in_archive": "historical_french",
"description": "17-19th century French prints from Calamari-OCR/calamari_models (5-fold ensemble, nlbin, NFC)",
"size": 87335250,
"version_range": ">= 1.0.0"
"size": 30257128,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/idiotikon.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/idiotikon.tar.gz",
"type": "archive",
"name": "idiotikon",
"path_in_archive": "idiotikon",
"description": "Antiqua UW3 finetuned on Antiqua Idiotikon dictionary with many diacritics from Calamari-OCR/calamari_models (5-fold ensemble, nlbin, NFD)",
"size": 100807764,
"version_range": ">= 1.0.0"
"size": 30474541,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/1.1/uw3-modern-english.zip",
"url": "https://github.com/Calamari-OCR/calamari_models/releases/download/2.2/uw3-modern-english.tar.gz",
"type": "archive",
"name": "uw3-modern-english",
"path_in_archive": "uw3-modern-english",
"description": "Antiqua UW3 corpus from Calamari-OCR/calamari_models (5-fold ensemble, nlbin, NFC)",
"size": 85413520,
"version_range": ">= 1.0.0"
}
"size": 29897592,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_fraktur19.tar.gz",
"type": "archive",
"name": "deep3_fraktur19",
"path_in_archive": "deep3_fraktur19",
"description": "Model trained on 19th century German Fraktur, like zpd-fraktur19 but deeper (5-fold ensemble, nlbin, NFC) - val_CER=0.5%",
"size": 92555871,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_fraktur-hist.tar.gz",
"type": "archive",
"name": "deep3_fraktur-hist",
"path_in_archive": "deep3_fraktur-hist",
"description": "Model trained on 16th to 19th century German Fraktur, like fraktur-historical but deeper (5-fold ensemble, nlbin, NFC) - val_CER=0.9%",
"size": 92504515,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_antiqua-hist.tar.gz",
"type": "archive",
"name": "deep3_antiqua-hist",
"path_in_archive": "deep3_antiqua-hist",
"description": "Model trained on 16th to 19th century Antiqua, like antiqua-historical but deeper (5-fold ensemble, nlbin, NFC) - val_CER=0.5%",
"size": 92614001,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_antiqua-15-16-cent.tar.gz",
"type": "archive",
"name": "deep3_antiqua-15-16-cent",
"path_in_archive": "deep3_antiqua-15-16-cent",
"description": "Model trained on 15th and 16th century Latin Antiqua, like zpd-latin-script-hist-3 but deeper (5-fold ensemble, nlbin, NFC) - val_CER=0.5%",
"size": 92627999,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_lsh4.tar.gz",
"type": "archive",
"name": "deep3_lsh4",
"path_in_archive": "deep3_lsh4",
"description": "Model trained on 15th and 19th century on German, Latin, French etc. in Antiqua and Fraktur, like gt4histocr but deeper (5-fold ensemble, nlbin, NFC) - val_CER=1.6%",
"size": 92579708,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_htr-bastard.tar.gz",
"type": "archive",
"name": "deep3_htr-bastard",
"path_in_archive": "deep3_htr-bastard",
"description": "Model trained on 13th to 16th century German Gothic Bastarda (5-fold ensemble, nlbin, NFC) - val_CER=6.7%",
"size": 91539649,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/deep3_htr-gothic.tar.gz",
"type": "archive",
"name": "deep3_htr-gothic",
"path_in_archive": "deep3_htr-gothic",
"description": "Model trained on 13th to 16th century German Gothic Cursiva (5-fold ensemble, nlbin, NFC) - val_CER=2.5%",
"size": 91499098,
"version_range": ">= 2.0.0"
},
{
"url": "https://github.com/Calamari-OCR/calamari_models_experimental/releases/download/v0.0.3/def_arabic.tar.gz",
"type": "archive",
"name": "def_arabic",
"path_in_archive": "def_arabic",
"description": "Model trained for Arabic on ? (5-fold ensemble, nlbin, NFC) - val_CER=1.2%",
"size": 30651139,
"version_range": ">= 2.0.0"
}
]
}
}
Expand Down
Loading