From 12be9834872f511f61a2c17b836ce2a8988d2898 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sun, 12 Jul 2026 03:49:41 +0200 Subject: [PATCH] =?UTF-8?q?cnn-rnn-ocr=20inference:=20switch=20back=20to?= =?UTF-8?q?=20beam=20search,=20only=20run=20in=20TF=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - training.models.CTCDecoder: prefer beam search over greedy (because it is more accurate) - training reload makefile: skip ONNX and TF-Serving conversion for cnn-rnn-ocr models (because these would not work) - training reload makefile: default to onnx and tf conversions for all models (tf for training and onnx for inference) instead of tf-serving export --- src/eynollah/training/models.py | 4 +++- src/eynollah/training/reload-models-v0.8.mk | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/eynollah/training/models.py b/src/eynollah/training/models.py index eda6b0f..9076f0a 100644 --- a/src/eynollah/training/models.py +++ b/src/eynollah/training/models.py @@ -85,9 +85,11 @@ class CTCDecoder(Layer): # tf.compat.v1.nn.ctc_beam_search_decoder() also needs merge_repeated=False # tf.nn.ctc_beam_search_decoder() is not supported by ONNX, yet # tf.nn.ctc_greedy_decoder() is not as precise, though: - decoded, logits = tf.nn.ctc_greedy_decoder( + decoded, logits = tf.nn.ctc_beam_search_decoder( inputs, lengths, + beam_width=10, + top_paths=1 ) # get top path for all sequences in batch decoded = decoded[0] diff --git a/src/eynollah/training/reload-models-v0.8.mk b/src/eynollah/training/reload-models-v0.8.mk index 342d211..eab5ffb 100644 --- a/src/eynollah/training/reload-models-v0.8.mk +++ b/src/eynollah/training/reload-models-v0.8.mk @@ -23,7 +23,9 @@ CURRENT_MODELS += eynollah-binarization_20210425 CURRENT_MODELS += eynollah-column-classifier_20210425 CURRENT_MODELS += eynollah-enhancement_20210425 -all: tf-serving +# tf (SavedModel format) for training +# onnx conversion for fast inference +all: tf onnx tf-serving: $(CURRENT_MODELS:%=$(MODELS_DST)/%) tf: $(CURRENT_MODELS:%=$(MODELS_DST)/%) @@ -31,8 +33,11 @@ keras: $(CURRENT_MODELS:%=$(MODELS_DST)/%.keras) hdf5: $(CURRENT_MODELS:%=$(MODELS_DST)/%.h5) onnx: $(CURRENT_MODELS:%=$(MODELS_DST)/%.onnx) -$(MODELS_DST)/%: FORMAT = $(or $(filter tf,$(MAKECMDGOALS)), tf-serving) +# distinguish tf from tf-serving: target pattern is the same, +# so check if either is current goal, otherwise assumg tf +$(MODELS_DST)/%: FORMAT = $(or $(filter tf-serving,$(MAKECMDGOALS)), tf) $(MODELS_DST)/%: $(MODELS_SRC)/% + $(if $(and $(filter tf-serving,$(FORMAT)),$(findstring _ocr,$@)),$(warning skipping $@: OCR CTC decoder fails in TF-Serving) : )\ eynollah-training convert \ $(and $(wildcard $ $(notdir $<).hdf5.log 2>&1 || { cat $(notdir $<).hdf5.log; false; } $(MODELS_DST)/%.onnx: $(MODELS_SRC)/% + $(if $(findstring _ocr,$@),$(warning skipping $@: OCR CTC decoder is buggy in ONNX) : )\ eynollah-training convert \ $(and $(wildcard $