nathansut1/sbb-binarization-onnx
By nathansut1 · ↓ 0 · ♥ 0 · Updated 2026-03-19
What's in this repo
This page lists the files in nathansut1/sbb-binarization-onnx, including model_convtranspose.onnx.
- 1 ONNX models (.onnx files)
- 6 files, including 3 .py, 1 .md, 1 .onnx
- Last updated 2026-03-19
ONNX files
| File | Size | Download |
|---|---|---|
| model_convtranspose.onnx | — | Download |
How to use
These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.
README
SBB Binarization — ONNX Model
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.
What's here
- model_convtranspose.onnx — the model, ready to use with ONNX Runtime
- fix_onnx.py — the script that converts SBB's TensorFlow SavedModel to this ONNX file
- sample_workflow.py — minimal example showing how to binarize an image
- example_gpu_pipeline.py — full GPU pipeline using CuPy for production use
Quick start
pip install onnxruntime-gpu numpy Pillow
python3 sample_workflow.py input.jpg output.tif
What was changed from the original
The original TF model doesn't convert cleanly to ONNX for TensorRT. Three things needed fixing:
- Reshape batch dimension — tf2onnx hardcoded -2048 instead of -1 for dynamic batching
- Resize node attributes — TF-specific modes that TensorRT doesn't support, swapped to standard ONNX equivalents
- Resize to ConvTranspose — replaced nearest-neighbor upsampling with equivalent depthwise ConvTranspose ops so TensorRT can compile the model as a single subgraph instead of splitting it into 8+ pieces
All of this is in fix_onnx.py. To reproduce from scratch:
pip install tf2onnx onnx tensorflow
python3 -m tf2onnx.convert --saved-model path/to/saved_model/2022-08-16 --output model.onnx --opset 17
python3 fix_onnx.py model.onnx model_convtranspose.onnx
Output is <0.01% pixel difference from the original TF model.
License
Same as the original — Apache 2.0. All credit to the SBB team and the QURATOR project for the model itself.
Model info
Created: 2026-03-19
Updated: 2026-03-19
View on Hugging FaceFiles (6)
Related models
More from nathansut1
No other models by this author.
More models
No task type declared.