{"record":{"id":"3f2124d131729cbc","repo":"PaddlePaddle/PaddleOCR","slug":"unexpected-det-output-dims-dims-join","errorCode":null,"errorMessage":"Unexpected det output dims: [${dims.join(\", \")}]","messagePattern":"Unexpected det output dims: \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/models/det.ts","lineNumber":345,"sourceCode":"  const chw = toBgrFloatCHWFromBgr(bgr.data, dstW, dstH, config.normalize);\n  resized.delete();\n  bgr.delete();\n\n  return {\n    tensor: new ort.Tensor(\"float32\", chw, [1, 3, dstH, dstW]),\n    srcW,\n    srcH,\n    dstW,\n    dstH\n  };\n}\n\nfunction getDetMap(outputTensor: Tensor): { data: Float32Array; h: number; w: number } {\n  const dims = outputTensor.dims;\n  const data = outputTensor.data as Float32Array;\n  if (dims.length === 4) return { data, h: dims[2], w: dims[3] };\n  if (dims.length === 3) return { data, h: dims[1], w: dims[2] };\n  throw new Error(`Unexpected det output dims: [${dims.join(\", \")}]`);\n}\n\nfunction createBatchDetTensor(\n  ort: OrtModule,\n  preps: DetPreprocessResult[],\n  maxH: number,\n  maxW: number\n): Tensor {\n  const batch = preps.length;\n  const plane = 3 * maxH * maxW;\n  const out = new Float32Array(batch * plane);\n  for (let i = 0; i < batch; i += 1) {\n    const prep = preps[i];\n    const chw = prep.tensor.data as Float32Array;\n    const { dstH, dstW } = prep;\n    const base = i * plane;\n    for (let c = 0; c < 3; c += 1) {\n      const srcChannelBase = c * dstH * dstW;","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/models/det.ts#L327-L363","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isDetMapDims(dims: readonly number[]): dims is [number, number, number] | [number, number, number, number] {\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    // model/layout mismatch: switch back to the bundled det ONNX asset\n  } else throw e;\n}","preventionTips":["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"],"tags":["paddleocr","onnxruntime","detection","model-mismatch","tensor-shape"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}