cnn-rnn-ocr inference: switch back to beam search, only run in TF…

- 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
This commit is contained in:
Robert Sachunsky 2026-07-12 03:49:41 +02:00
parent c680dae2d1
commit 12be983487
2 changed files with 11 additions and 3 deletions

View file

@ -85,9 +85,11 @@ class CTCDecoder(Layer):
# tf.compat.v1.nn.ctc_beam_search_decoder() also needs merge_repeated=False # 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_beam_search_decoder() is not supported by ONNX, yet
# tf.nn.ctc_greedy_decoder() is not as precise, though: # 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, inputs,
lengths, lengths,
beam_width=10,
top_paths=1
) )
# get top path for all sequences in batch # get top path for all sequences in batch
decoded = decoded[0] decoded = decoded[0]

View file

@ -23,7 +23,9 @@ CURRENT_MODELS += eynollah-binarization_20210425
CURRENT_MODELS += eynollah-column-classifier_20210425 CURRENT_MODELS += eynollah-column-classifier_20210425
CURRENT_MODELS += eynollah-enhancement_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-serving: $(CURRENT_MODELS:%=$(MODELS_DST)/%)
tf: $(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) hdf5: $(CURRENT_MODELS:%=$(MODELS_DST)/%.h5)
onnx: $(CURRENT_MODELS:%=$(MODELS_DST)/%.onnx) 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)/% $(MODELS_DST)/%: $(MODELS_SRC)/%
$(if $(and $(filter tf-serving,$(FORMAT)),$(findstring _ocr,$@)),$(warning skipping $@: OCR CTC decoder fails in TF-Serving) : )\
eynollah-training convert \ eynollah-training convert \
$(and $(wildcard $</config.json),--rebuild) \ $(and $(wildcard $</config.json),--rebuild) \
--in $< \ --in $< \
@ -57,6 +62,7 @@ $(MODELS_DST)/%.h5: $(MODELS_SRC)/%
> $(notdir $<).hdf5.log 2>&1 || { cat $(notdir $<).hdf5.log; false; } > $(notdir $<).hdf5.log 2>&1 || { cat $(notdir $<).hdf5.log; false; }
$(MODELS_DST)/%.onnx: $(MODELS_SRC)/% $(MODELS_DST)/%.onnx: $(MODELS_SRC)/%
$(if $(findstring _ocr,$@),$(warning skipping $@: OCR CTC decoder is buggy in ONNX) : )\
eynollah-training convert \ eynollah-training convert \
$(and $(wildcard $</config.json),--rebuild) \ $(and $(wildcard $</config.json),--rebuild) \
--in $< \ --in $< \