Baidu's 6 MB OCR Model Runs Entirely in the Browser with No Backend
Client-side OCR at 6 MB removes the operational overhead of deploying, scaling, and paying for a Python inference service. For internal tools and low-volume apps, the browser handles the GPU work directly, and the model is small enough to load over a spotty connection without a noticeable wait.
Baidu's PP-OCRv6 tiny packs a text-detection model (1.74 MB) and a text-recognition model (4.28 MB) into a combined 6 MB payload that loads in the browser and runs inference through ONNX Runtime Web on WebGL or WebGPU. The pipeline resizes images, runs DBNet-based detection with binarization and connected-component post-processing, then feeds cropped text regions into a CRNN recognizer with CTC greedy decoding. The entire flow—upload, detect, recognize, display—happens client-side with no backend service.
Three concrete pitfalls surfaced during the build. A mismatched character dictionary caused garbled output because the ONNX model outputs 6,906 classes but the downloaded dictionary held only 6,622 entries; extracting the character set directly from the model's protobuf metadata fixed it. NaN values in model output propagated through softmax and required explicit finite-value guards during argmax and exponentiation. A 0.3 confidence threshold on softmax over 6,906 dimensions wiped out all results because per-character probabilities rarely exceed 0.05.
Switching to the small model variant broke the frontend post-processing entirely: small uses a single-channel binary map with contour detection instead of DBNet's three-channel probability map and unclip expansion, so the detection pipeline needs a rewrite.
Running a production-grade OCR pipeline in the browser at 6 MB is a genuine alternative to server-side deployment for many internal tools, not just a demo trick.
The jump from tiny to small is not a drop-in upgrade; the detection head architecture changes completely, which means model selection locks in your post-processing code.
Extracting character sets from ONNX metadata is a more reliable pattern than shipping a separate dictionary file that can drift from the model's actual output classes.
Softmax over very large vocabularies (6,906 classes) produces per-class probabilities so low that conventional confidence thresholds become meaningless without recalibration.