StagesDetect

DbnetOnnxDetector

The same DBNet ONNX text detector ScaleDP runs server-side, in the browser. Rotated, line-level boxes.

Import
import { DbnetOnnxDetector } from '@stabrise/scaledp/ocr'
Group
Detect
Reads
image
Writes
boxes
Needs
onnxruntime-web

A direct mirror of ScaleDP's DBNetOnnxDetector — same model, same thresholds — so a detection result can be compared across the two runtimes. About 4.8 MB.

import { Pipeline } from '@stabrise/scaledp'
import { PdfToImage } from '@stabrise/scaledp/pdf'
import { DbnetOnnxDetector, TesseractRecognizer } from '@stabrise/scaledp/ocr'

const rows = await new Pipeline([
    new PdfToImage(),
    new DbnetOnnxDetector({ outputCol: 'boxes' }),
    new TesseractRecognizer({ inputCols: ['image', 'boxes'] }),
]).transform(file)
Open in builder

Unlike Paddle's, these boxes carry a real rotation, which is what makes the detector worth its download on skewed scans.

The three thresholds

They are easy to confuse, and they act at different points:

  • binaryThreshold (0.5) is per pixel: above this, a pixel counts as text in the probability map. Raise it to break apart touching lines; lower it to stop thin strokes from being lost.
  • scoreThreshold (0.3) is per candidate: the mean in-box probability a region must reach to be kept at all.
  • unclipRatio (2.5) is a size: DB shrinks regions during training, so every candidate is grown back by this ratio. Too low clips descenders; too high merges neighbours.

mergeBoxes then merges overlapping boxes that share a line; ScaleDP uses an IoU of 0.02 for this.

A Python bug not reproduced

In ScaleDP, scoreThreshold never reaches DBPostProcess — the effective threshold is the hardcoded 0.3. Here the parameter is wired through, so setting it does something.

Self-hosting

model accepts a Hugging Face repo id or a URL. A URL is treated as a single-file model spec and bypasses modelHost entirely.

Preprocessing, for the record

Letterboxed to 1280×1280 padding at the end, white fill, then normalised with ImageNet mean and standard deviation in BGR channel order. That last part reproduces a quirk of the Python implementation — BGR pixels with RGB statistics — and is required for parity. It is not a bug on this side.

Parameters

ParameterTypeDefaultMeaning
model'StabRise/text_detection_dbnet_ml_v0.2' | 'StabRise/text_detection_dbnet_ml_v0.1''StabRise/text_detection_dbnet_ml_v0.2'Hugging Face repo id, or a URL when self-hosting.
scoreThresholdnumber 0–10.3Mean in-box probability a candidate must reach.
binaryThresholdnumber 0–10.5Probability above which a pixel counts as text.
unclipRationumber 0.5–52.5How far to grow each box; DB shrinks text regions during training.
mergeBoxesbooleantrueMerge overlapping boxes that share a line. Usually changes nothing here — this model already returns one region per line, so no two boxes overlap.

On this page