predictor for OCR models: work around ONNX bug …

(ONNX converted models already return `np.dtype=object`
 arrays of `np.str_` instead of `np.bytes_`; so undo this)
This commit is contained in:
Robert Sachunsky 2026-06-26 02:42:51 +02:00
parent 948d841a7d
commit 01e69a0e22

View file

@ -195,6 +195,10 @@ class Predictor(mp.context.SpawnProcess):
# convert tf.string/np.object to fixed-length bytes # convert tf.string/np.object to fixed-length bytes
# (because object segfaults in shm) # (because object segfaults in shm)
if x.dtype is np.dtype(object): 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.astype(bytes)
return x return x
if isinstance(result, (list, tuple)): if isinstance(result, (list, tuple)):