Skip to content

Commit

Permalink
processor: self.resolve_resource model in addition to SBB_BINARIZE_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Jan 28, 2021
1 parent ea69494 commit 4ceed75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
numpy >= 1.17.0, < 1.19.0
setuptools >= 41
opencv-python-headless
ocrd >= 2.18.0
ocrd >= 2.22.3
keras >= 2.3.1, < 2.4
h5py < 3
tensorflow-gpu >= 1.15, < 1.16
10 changes: 6 additions & 4 deletions sbb_binarize/ocrd_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ def __init__(self, *args, **kwargs):
kwargs['ocrd_tool'] = OCRD_TOOL['tools'][TOOL]
kwargs['version'] = OCRD_TOOL['version']
if not(kwargs.get('show_help', None) or kwargs.get('dump_json', None) or kwargs.get('show_version')):
LOG = getLogger('processor.SbbBinarize.__init__')
if not 'model' in kwargs['parameter']:
raise ValueError("'model' parameter is required")
model_path = Path(kwargs['parameter']['model'])
if not model_path.is_absolute():
if 'SBB_BINARIZE_DATA' in environ:
if 'SBB_BINARIZE_DATA' in environ and environ['SBB_BINARIZE_DATA']:
LOG.info("Environment variable SBB_BINARIZE_DATA is set to '%s' - prepending to model value '%s'. If you don't want this mechanism, unset the SBB_BINARIZE_DATA environment variable.", environ['SBB_BINARIZE_DATA'], model_path)
model_path = Path(environ['SBB_BINARIZE_DATA']).joinpath(model_path)
model_path = model_path.resolve()
if not model_path.is_dir():
raise FileNotFoundError("Does not exist or is not a directory: %s" % model_path)
if not model_path.is_dir():
raise FileNotFoundError("Does not exist or is not a directory: %s" % model_path)
kwargs['parameter']['model'] = str(model_path)
super().__init__(*args, **kwargs)

Expand All @@ -61,7 +63,7 @@ def process(self):
assert_file_grp_cardinality(self.output_file_grp, 1)

oplevel = self.parameter['operation_level']
model_path = self.parameter['model'] # pylint: disable=attribute-defined-outside-init
model_path = self.resolve_resource(self.parameter['model'])
binarizer = SbbBinarizer(model_dir=model_path, logger=LOG)

for n, input_file in enumerate(self.input_files):
Expand Down

0 comments on commit 4ceed75

Please sign in to comment.