From 01e69a0e221d644fc2142d8a620be25d6a699899 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 26 Jun 2026 02:42:51 +0200 Subject: [PATCH] =?UTF-8?q?predictor=20for=20OCR=20models:=20work=20around?= =?UTF-8?q?=20ONNX=20bug=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (ONNX converted models already return `np.dtype=object` arrays of `np.str_` instead of `np.bytes_`; so undo this) --- src/eynollah/predictor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/eynollah/predictor.py b/src/eynollah/predictor.py index 6b7fe96..9121ffe 100644 --- a/src/eynollah/predictor.py +++ b/src/eynollah/predictor.py @@ -195,6 +195,10 @@ class Predictor(mp.context.SpawnProcess): # convert tf.string/np.object to fixed-length bytes # (because object segfaults in shm) if x.dtype is np.dtype(object): + # ONNX conversion for some reason decodes bytes into str already + # so here we undo this, too + if x[0].dtype is np.dtype(object) and isinstance(x[0, 0], str): + x = np.char.encode(x.astype(str), 'utf-8') return x.astype(bytes) return x if isinstance(result, (list, tuple)):