ONNX conversion of
SBB/sbb_binarization by the Berlin State Library (Staatsbibliothek zu Berlin), developed as part of the
QURATOR project.
The original model is a UNet + Vision Transformer hybrid that converts scanned document images to black and white for OCR. It works on 448x448 patches.
1pip install onnxruntime-gpu numpy Pillow
2python3 sample_workflow.py input.jpg output.tif
The original TF model doesn't convert cleanly to ONNX for TensorRT. Three things needed fixing:
1pip install tf2onnx onnx tensorflow
2python3 -m tf2onnx.convert --saved-model path/to/saved_model/2022-08-16 --output model.onnx --opset 17
3python3 fix_onnx.py model.onnx model_convtranspose.onnx
Output is <0.01% pixel difference from the original TF model.
Same as the original —
Apache 2.0. All credit to the SBB team and the QURATOR project for the model itself.