{"record":{"id":"f4e9e913df654bee","repo":"PaddlePaddle/PaddleOCR","slug":"unexpected-det-output-dims-od-join","errorCode":null,"errorMessage":"Unexpected det output dims: [${od.join(\", \")}]","messagePattern":"Unexpected det output dims: \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/models/det.ts","lineNumber":428,"sourceCode":"  const base = batchDetOutputPlaneOffset(dims, batchIndex);\n  const out = new Float32Array(cropOh * cropOw);\n  for (let r = 0; r < cropOh; r += 1) {\n    const rowStart = base + r * owFull;\n    out.set(data.subarray(rowStart, rowStart + cropOw), r * cropOw);\n  }\n  return new ort.Tensor(\"float32\", out, [1, 1, cropOh, cropOw]);\n}\n\nfunction postprocess(\n  context: DetRunContext,\n  fullOutput: Tensor,\n  preps: DetPreprocessResult[],\n  params: InternalDetParams\n): InternalDetBatchItem[] {\n  const { cv, ort, config } = context;\n  const od = fullOutput.dims;\n  if (od.length !== 3 && od.length !== 4) {\n    throw new Error(`Unexpected det output dims: [${od.join(\", \")}]`);\n  }\n  const ohFull = od.length === 4 ? od[2] : od[1];\n  const owFull = od.length === 4 ? od[3] : od[2];\n  const nOut = od.length === 4 ? od[0] : preps.length === 1 ? 1 : od[0];\n  if (nOut !== preps.length) {\n    throw new Error(\n      `Detection batch output N=${String(nOut)} does not match input batch ${String(preps.length)}`\n    );\n  }\n\n  const maxH = Math.max(...preps.map((p) => p.dstH));\n  const maxW = Math.max(...preps.map((p) => p.dstW));\n\n  const items: InternalDetBatchItem[] = [];\n  for (let i = 0; i < preps.length; i += 1) {\n    const prep = preps[i];\n    const { cropOh, cropOw } = detFeatureCropDims(prep.dstH, prep.dstW, maxH, maxW, ohFull, owFull);\n    const planeTensor = sliceBatchedDetOutputPlane(","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/models/det.ts#L410-L446","documentation":"Thrown by postprocess() in the det pipeline: the full batched output tensor must be rank 3 or 4 so the code can extract batch (N), height, and width axes. A different rank means the ONNX graph output layout is incompatible with this postprocessor — effectively the same failure class as the getDetMap guard, but on the batched path before per-sample slicing.","triggerScenarios":"Running batched detection inference where the model's output tensor is rank 2 (e.g. [N, H*W]) or rank 5; caused by a custom-exported det model, a wrong model file, or an ORT version that reshapes outputs differently.","commonSituations":"Replacing the bundled det ONNX with a re-export using different opset/export options; using a dynamic-shape model whose output collapses dims at batch=1; version drift between paddleocr-js core and the model files.","solutions":["Restore the det model ONNX file that matches this package version and retry","If a custom export is required, keep the output as [N, C, H, W] (rank 4)","Print the offending dims (already included in the message) and check whether N/H/W were collapsed during export","Confirm no pre/post transform node (reshape/squeeze) was added to the model graph tail"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isBatchedDetDims(dims: readonly number[]): boolean {\n  return dims.length === 3 || dims.length === 4;\n}","tryCatchPattern":"try { await detModel.predict(cv, mats); } catch (e) {\n  if (e instanceof Error && /Unexpected det output dims/.test(e.message)) {\n    // wrong det model or altered export: restore matching model asset\n  } else throw e;\n}","preventionTips":["Validate third-party det models with a single-image run before batching in production","Avoid adding reshape/squeeze nodes when re-exporting detection graphs","Record the package version alongside every model asset you deploy"],"tags":["paddleocr","onnxruntime","detection","model-mismatch","tensor-shape","batching"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}