This commit is contained in:
kba 2025-10-27 11:44:59 +01:00
parent ec1fd93dad
commit 51d2680d9c
3 changed files with 14 additions and 16 deletions

View file

@ -21,8 +21,8 @@ DEFAULT_MODEL_SPECS = EynollahModelSpecSet([
EynollahModelSpec( EynollahModelSpec(
category="binarization", category="binarization",
variant='', variant='hybrid',
filename="models_eynollah/eynollah-binarization-hybrid_20230504", filename="models_eynollah/eynollah-binarization-hybrid_20230504/model_bin_hybrid_trans_cnn_sbb_ens",
dists=['layout', 'binarization', ], dists=['layout', 'binarization', ],
dist_url=dist_url("binarization"), dist_url=dist_url("binarization"),
type=KerasModel, type=KerasModel,
@ -39,7 +39,7 @@ DEFAULT_MODEL_SPECS = EynollahModelSpecSet([
EynollahModelSpec( EynollahModelSpec(
category="binarization", category="binarization",
variant='augment', variant='',
filename="models_eynollah/eynollah-binarization_20210425", filename="models_eynollah/eynollah-binarization_20210425",
dists=['binarization'], dists=['binarization'],
dist_url=dist_url("binarization"), dist_url=dist_url("binarization"),

View file

@ -27,7 +27,7 @@ class SbbBinarizer:
def __init__(self, model_dir: str, mode: str, logger=None): def __init__(self, model_dir: str, mode: str, logger=None):
if mode not in ('single', 'multi'): if mode not in ('single', 'multi'):
raise ValueError(f"'mode' must be either 'multi' or 'single', not {mode}") 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.model_zoo = EynollahModelZoo(basedir=model_dir)
self.models = self.setup_models(mode) self.models = self.setup_models(mode)
self.session = self.start_new_session() self.session = self.start_new_session()
@ -51,8 +51,7 @@ class SbbBinarizer:
self.session.close() self.session.close()
del self.session del self.session
def predict(self, img, use_patches, n_batch_inference=5): def predict(self, model, img, use_patches, n_batch_inference=5):
model = self.model_zoo.get('binarization', Model)
model_height = model.layers[len(model.layers)-1].output_shape[1] model_height = model.layers[len(model.layers)-1].output_shape[1]
model_width = model.layers[len(model.layers)-1].output_shape[2] model_width = model.layers[len(model.layers)-1].output_shape[2]

View file

@ -16,8 +16,7 @@ from ocrd_models.constants import NAMESPACES as NS
testdir = Path(__file__).parent.resolve() testdir = Path(__file__).parent.resolve()
MODELS_OCR = environ.get('MODELS_OCR', str(testdir.joinpath('..', 'models_ocr_v0_6_0').resolve())) MODELS_DIR = environ.get('EYNOLLAH_MODELS_DIR', str(testdir.joinpath('..').resolve()))
MODELS_BIN = environ.get('MODELS_BIN', str(testdir.joinpath('..', 'default-2021-03-09').resolve()))
def only_eynollah(logrec): def only_eynollah(logrec):
return logrec.name.startswith('eynollah') 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') infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif')
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png')
args = [ args = [
'-m', MODELS_BIN, '-m', MODELS_DIR,
'-i', str(infile), '-i', str(infile),
'-o', str(outfile), '-o', str(outfile),
] ]
@ -56,7 +55,7 @@ def test_run_eynollah_binarization_directory(tmp_path, pytestconfig, caplog):
indir = testdir.joinpath('resources') indir = testdir.joinpath('resources')
outdir = tmp_path outdir = tmp_path
args = [ args = [
'-m', MODELS_BIN, '-m', MODELS_DIR,
'-di', str(indir), '-di', str(indir),
'-o', str(outdir), '-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') infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif')
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png')
args = [ args = [
'-m', MODELS_LAYOUT, '-m', MODELS_DIR,
'-i', str(infile), '-i', str(infile),
'-o', str(outfile.parent), '-o', str(outfile.parent),
] ]
@ -105,7 +104,7 @@ def test_run_eynollah_enhancement_directory(tmp_path, pytestconfig, caplog):
indir = testdir.joinpath('resources') indir = testdir.joinpath('resources')
outdir = tmp_path outdir = tmp_path
args = [ args = [
'-m', MODELS_LAYOUT, '-m', MODELS_DIR,
'-di', str(indir), '-di', str(indir),
'-o', str(outdir), '-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') infile = testdir.joinpath('resources/kant_aufklaerung_1784_0020.xml')
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.xml') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.xml')
args = [ args = [
'-m', MODELS_LAYOUT, '-m', MODELS_DIR,
'-i', str(infile), '-i', str(infile),
'-o', str(outfile.parent), '-o', str(outfile.parent),
] ]
@ -151,7 +150,7 @@ def test_run_eynollah_mbreorder_directory(tmp_path, pytestconfig, caplog):
indir = testdir.joinpath('resources') indir = testdir.joinpath('resources')
outdir = tmp_path outdir = tmp_path
args = [ args = [
'-m', MODELS_LAYOUT, '-m', MODELS_DIR,
'-di', str(indir), '-di', str(indir),
'-o', str(outdir), '-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 = tmp_path.joinpath('render').joinpath('kant_aufklaerung_1784_0020.png')
outrenderfile.parent.mkdir() outrenderfile.parent.mkdir()
args = [ args = [
'-m', MODELS_OCR, '-m', MODELS_DIR,
'-i', str(infile), '-i', str(infile),
'-dx', str(infile.parent), '-dx', str(infile.parent),
'-o', str(outfile.parent), '-o', str(outfile.parent),
@ -212,7 +211,7 @@ def test_run_eynollah_ocr_directory(tmp_path, pytestconfig, caplog):
indir = testdir.joinpath('resources') indir = testdir.joinpath('resources')
outdir = tmp_path outdir = tmp_path
args = [ args = [
'-m', MODELS_OCR, '-m', MODELS_DIR,
'-di', str(indir), '-di', str(indir),
'-dx', str(indir), '-dx', str(indir),
'-o', str(outdir), '-o', str(outdir),