From 51d2680d9c8ef1f61ed653707bbb01c66872c666 Mon Sep 17 00:00:00 2001 From: kba Date: Mon, 27 Oct 2025 11:44:59 +0100 Subject: [PATCH] wip --- src/eynollah/model_zoo/default_specs.py | 6 +++--- src/eynollah/sbb_binarize.py | 5 ++--- tests/test_run.py | 19 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/eynollah/model_zoo/default_specs.py b/src/eynollah/model_zoo/default_specs.py index a57f7f1..fa67393 100644 --- a/src/eynollah/model_zoo/default_specs.py +++ b/src/eynollah/model_zoo/default_specs.py @@ -21,8 +21,8 @@ DEFAULT_MODEL_SPECS = EynollahModelSpecSet([ EynollahModelSpec( category="binarization", - variant='', - filename="models_eynollah/eynollah-binarization-hybrid_20230504", + variant='hybrid', + filename="models_eynollah/eynollah-binarization-hybrid_20230504/model_bin_hybrid_trans_cnn_sbb_ens", dists=['layout', 'binarization', ], dist_url=dist_url("binarization"), type=KerasModel, @@ -39,7 +39,7 @@ DEFAULT_MODEL_SPECS = EynollahModelSpecSet([ EynollahModelSpec( category="binarization", - variant='augment', + variant='', filename="models_eynollah/eynollah-binarization_20210425", dists=['binarization'], dist_url=dist_url("binarization"), diff --git a/src/eynollah/sbb_binarize.py b/src/eynollah/sbb_binarize.py index 48dc7b1..da165ea 100644 --- a/src/eynollah/sbb_binarize.py +++ b/src/eynollah/sbb_binarize.py @@ -27,7 +27,7 @@ class SbbBinarizer: def __init__(self, model_dir: str, mode: str, logger=None): if mode not in ('single', 'multi'): raise ValueError(f"'mode' must be either 'multi' or 'single', not {mode}") - self.log = logger if logger else logging.getLogger('SbbBinarizer') + self.log = logger if logger else logging.getLogger('eynollah.binarization') self.model_zoo = EynollahModelZoo(basedir=model_dir) self.models = self.setup_models(mode) self.session = self.start_new_session() @@ -51,8 +51,7 @@ class SbbBinarizer: self.session.close() del self.session - def predict(self, img, use_patches, n_batch_inference=5): - model = self.model_zoo.get('binarization', Model) + def predict(self, model, img, use_patches, n_batch_inference=5): model_height = model.layers[len(model.layers)-1].output_shape[1] model_width = model.layers[len(model.layers)-1].output_shape[2] diff --git a/tests/test_run.py b/tests/test_run.py index 359b0f0..6d97fbb 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -16,8 +16,7 @@ from ocrd_models.constants import NAMESPACES as NS testdir = Path(__file__).parent.resolve() -MODELS_OCR = environ.get('MODELS_OCR', str(testdir.joinpath('..', 'models_ocr_v0_6_0').resolve())) -MODELS_BIN = environ.get('MODELS_BIN', str(testdir.joinpath('..', 'default-2021-03-09').resolve())) +MODELS_DIR = environ.get('EYNOLLAH_MODELS_DIR', str(testdir.joinpath('..').resolve())) def only_eynollah(logrec): return logrec.name.startswith('eynollah') @@ -32,7 +31,7 @@ def test_run_eynollah_binarization_filename(tmp_path, pytestconfig, caplog, opti infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') args = [ - '-m', MODELS_BIN, + '-m', MODELS_DIR, '-i', str(infile), '-o', str(outfile), ] @@ -56,7 +55,7 @@ def test_run_eynollah_binarization_directory(tmp_path, pytestconfig, caplog): indir = testdir.joinpath('resources') outdir = tmp_path args = [ - '-m', MODELS_BIN, + '-m', MODELS_DIR, '-di', str(indir), '-o', str(outdir), ] @@ -81,7 +80,7 @@ def test_run_eynollah_enhancement_filename(tmp_path, pytestconfig, caplog, optio infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') args = [ - '-m', MODELS_LAYOUT, + '-m', MODELS_DIR, '-i', str(infile), '-o', str(outfile.parent), ] @@ -105,7 +104,7 @@ def test_run_eynollah_enhancement_directory(tmp_path, pytestconfig, caplog): indir = testdir.joinpath('resources') outdir = tmp_path args = [ - '-m', MODELS_LAYOUT, + '-m', MODELS_DIR, '-di', str(indir), '-o', str(outdir), ] @@ -124,7 +123,7 @@ def test_run_eynollah_mbreorder_filename(tmp_path, pytestconfig, caplog): infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.xml') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.xml') args = [ - '-m', MODELS_LAYOUT, + '-m', MODELS_DIR, '-i', str(infile), '-o', str(outfile.parent), ] @@ -151,7 +150,7 @@ def test_run_eynollah_mbreorder_directory(tmp_path, pytestconfig, caplog): indir = testdir.joinpath('resources') outdir = tmp_path args = [ - '-m', MODELS_LAYOUT, + '-m', MODELS_DIR, '-di', str(indir), '-o', str(outdir), ] @@ -181,7 +180,7 @@ def test_run_eynollah_ocr_filename(tmp_path, pytestconfig, caplog, options): outrenderfile = tmp_path.joinpath('render').joinpath('kant_aufklaerung_1784_0020.png') outrenderfile.parent.mkdir() args = [ - '-m', MODELS_OCR, + '-m', MODELS_DIR, '-i', str(infile), '-dx', str(infile.parent), '-o', str(outfile.parent), @@ -212,7 +211,7 @@ def test_run_eynollah_ocr_directory(tmp_path, pytestconfig, caplog): indir = testdir.joinpath('resources') outdir = tmp_path args = [ - '-m', MODELS_OCR, + '-m', MODELS_DIR, '-di', str(indir), '-dx', str(indir), '-o', str(outdir),