From 823b5923ac75977d223ad98c69baa971ffe5cb6b Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Mon, 11 Sep 2023 11:11:29 +0200 Subject: [PATCH 1/2] disable tensorflow/keras print-to-stdout with tf_disable_interactive_logs, OCR-D/core#1091 --- ocrd_calamari/config.py | 1 - ocrd_calamari/recognize.py | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ocrd_calamari/config.py b/ocrd_calamari/config.py index 6141ca2..01e0b23 100644 --- a/ocrd_calamari/config.py +++ b/ocrd_calamari/config.py @@ -2,4 +2,3 @@ from pkg_resources import resource_string OCRD_TOOL = json.loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8')) -TF_CPP_MIN_LOG_LEVEL = '3' # '3' == ERROR diff --git a/ocrd_calamari/recognize.py b/ocrd_calamari/recognize.py index 28a4e6c..bafe855 100644 --- a/ocrd_calamari/recognize.py +++ b/ocrd_calamari/recognize.py @@ -5,6 +5,21 @@ from glob import glob import numpy as np +from ocrd_utils import ( + assert_file_grp_cardinality, + concat_padded, + coordinates_for_segment, + getLogger, + make_file_id, + points_from_polygon, + polygon_from_x0y0x1y1, + MIMETYPE_PAGE, + tf_disable_interactive_logs, +) + +# Disable tensorflow/keras logging via print before importing calamari +tf_disable_interactive_logs() + from calamari_ocr import __version__ as calamari_version from calamari_ocr.ocr import MultiPredictor from calamari_ocr.ocr.voting import voter_from_proto @@ -18,12 +33,6 @@ WordType, GlyphType, CoordsType, to_xml ) -from ocrd_utils import ( - getLogger, concat_padded, - coordinates_for_segment, points_from_polygon, polygon_from_x0y0x1y1, - make_file_id, assert_file_grp_cardinality, - MIMETYPE_PAGE -) from ocrd_calamari.config import OCRD_TOOL, TF_CPP_MIN_LOG_LEVEL From 637a08da6a1118c79216333e805f209fc7ee8303 Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Thu, 12 Oct 2023 20:21:54 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20recognize.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config.py's TF_CPP_MIN_LOG_LEVEL was removed but recognize.py not adapted accordingly. Fix this by removing the use of the variable there as well. --- ocrd_calamari/recognize.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ocrd_calamari/recognize.py b/ocrd_calamari/recognize.py index bafe855..5a16c41 100644 --- a/ocrd_calamari/recognize.py +++ b/ocrd_calamari/recognize.py @@ -34,9 +34,8 @@ to_xml ) -from ocrd_calamari.config import OCRD_TOOL, TF_CPP_MIN_LOG_LEVEL +from ocrd_calamari.config import OCRD_TOOL -os.environ['TF_CPP_MIN_LOG_LEVEL'] = TF_CPP_MIN_LOG_LEVEL from tensorflow import __version__ as tensorflow_version TOOL = 'ocrd-calamari-recognize'