PaddlePaddle/PaddleOCR · error
Unexpected det output dims: [${dims.join(", ")}]
Error message
Unexpected det output dims: [${dims.join(", ")}] What it means
Thrown by getDetMap() when slicing the detection model's output tensor: the map interpretation supports only 4D [N,C,H,W] or 3D [C,H,W]/[N,H,W] layouts. Any other rank (e.g. a 2D tensor) means the ONNX model's output shape is not what the postprocessing code was written for — typically a wrong or re-exported detection model.
Source
Thrown at paddleocr-js/packages/core/src/models/det.ts:345
const chw = toBgrFloatCHWFromBgr(bgr.data, dstW, dstH, config.normalize);
resized.delete();
bgr.delete();
return {
tensor: new ort.Tensor("float32", chw, [1, 3, dstH, dstW]),
srcW,
srcH,
dstW,
dstH
};
}
function getDetMap(outputTensor: Tensor): { data: Float32Array; h: number; w: number } {
const dims = outputTensor.dims;
const data = outputTensor.data as Float32Array;
if (dims.length === 4) return { data, h: dims[2], w: dims[3] };
if (dims.length === 3) return { data, h: dims[1], w: dims[2] };
throw new Error(`Unexpected det output dims: [${dims.join(", ")}]`);
}
function createBatchDetTensor(
ort: OrtModule,
preps: DetPreprocessResult[],
maxH: number,
maxW: number
): Tensor {
const batch = preps.length;
const plane = 3 * maxH * maxW;
const out = new Float32Array(batch * plane);
for (let i = 0; i < batch; i += 1) {
const prep = preps[i];
const chw = prep.tensor.data as Float32Array;
const { dstH, dstW } = prep;
const base = i * plane;
for (let c = 0; c < 3; c += 1) {
const srcChannelBase = c * dstH * dstW;View on GitHub (pinned to 2661c7c0ef)
Solutions
- Use the detection model assets shipped or referenced by this paddleocr-js version
- If exporting your own model, ensure the output tensor retains a 3D or 4D layout ([N,C,H,W] preferred)
- Log the actual dims from the caught error and compare against the expected [batch,1,H,W]
- Verify you loaded the det model into the det slot and not a rec/cls model
Defensive patterns
Strategy: try-catch
Type guard
function isDetMapDims(dims: readonly number[]): dims is [number, number, number] | [number, number, number, number] {
return dims.length === 3 || dims.length === 4;
} Try / catch
try { await detModel.predict(cv, mats); } catch (e) {
if (e instanceof Error && /Unexpected det output dims/.test(e.message)) {
// model/layout mismatch: switch back to the bundled det ONNX asset
} else throw e;
} Prevention
- Do not substitute det ONNX files from other releases without checking output layout [N,C,H,W]
- Keep model assets and package version locked as a pair
- Run a one-image smoke test after any model swap to catch shape errors early
When it happens
Trigger: Substituting a custom or newer DBNet detection ONNX file whose graph output was squeezed/reshaped differently; loading a classifier or recognition model into the det slot; an ONNX Runtime version change altering dynamic-dim squeezing on the output.
Common situations: User swaps model_dir to a self-exported PaddleOCR det model without matching the expected output layout; mixed model versions (det model from one release, code from another); export with keepdims off producing rank-2 output.
Related errors
- Unexpected det output dims: [${od.join(", ")}]
- Detection batch output N=${String(nOut)} does not match inpu
- Unexpected rec output dims: [${dims.join(", ")}]
- Detection model session is not initialized.
- Recognition model session is not initialized.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/3f2124d131729cbc.
Report an issue: GitHub.