{"record":{"id":"891b56f09195e838","repo":"PaddlePaddle/PaddleOCR","slug":"recresizeimg-image-shape-is-required-in-rec-infere","errorCode":null,"errorMessage":"RecResizeImg.image_shape is required in rec inference.yml","messagePattern":"RecResizeImg\\.image_shape is required in rec inference\\.yml","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/models/rec.ts","lineNumber":78,"sourceCode":"export const DEFAULT_REC_RUNTIME_LIMITS = Object.freeze({});\n\nconst MAX_REC_WIDTH = 3200;\n\nexport const DEFAULT_REC_MODEL_CONFIG: Readonly<RecModelConfig> = Object.freeze({\n  ...DEFAULT_REC_MODEL_PARSE_FALLBACKS\n});\n\nexport function parseRecModelConfigText(text: string): RecModelConfig {\n  const parsed = parseInferenceConfigText(text);\n  const preProcess = parsed.PreProcess as Record<string, unknown> | undefined;\n  const transformOps = preProcess?.transform_ops as Array<Record<string, unknown>> | undefined;\n  const resize = getTransformOp(transformOps, \"RecResizeImg\");\n  const postprocess = (parsed.PostProcess || {}) as Record<string, unknown>;\n  const baseCharDict = postprocess.character_dict;\n\n  const imageShape = resize?.image_shape as number[] | undefined;\n  if (!imageShape || !Array.isArray(imageShape) || imageShape.length < 3) {\n    throw new Error(\"RecResizeImg.image_shape is required in rec inference.yml\");\n  }\n\n  const charDict =\n    Array.isArray(baseCharDict) && baseCharDict.length > 0\n      ? [...(baseCharDict as string[]), \" \"]\n      : [...DEFAULT_REC_ALPHANUMERIC_DICT, \" \"];\n\n  return {\n    imageShape,\n    charDict\n  };\n}\n\ninterface CreateRecModelArgs {\n  ort: OrtModule;\n  modelBytes: Uint8Array;\n  configText: string;\n  backend: string;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/models/rec.ts#L60-L96","documentation":"Thrown by parseRecModelConfigText() when parsing a recognition model's inference.yml: the PreProcess.transform_ops list must contain a RecResizeImg op with an image_shape array of at least 3 entries ([channels, height, width]). The rec preprocessing needs this shape to build its input tensor, so a config lacking it is rejected at load time rather than failing mid-inference.","triggerScenarios":"Loading a custom or older PP-OCRv rec model whose inference.yml omits RecResizeImg, renames it (e.g. DetResizeForTest), or has image_shape: [3, 48] (only 2 entries). Also triggered by a hand-edited YAML where the op was removed.","commonSituations":"Swapping in a rec model from a different PaddleOCR release with changed preprocessing op names; truncating the config when packaging assets; using a server-side (PaddleX-style) inference.yml that structures transform_ops differently.","solutions":["Open the rec model's inference.yml and confirm PreProcess.transform_ops includes RecResizeImg with image_shape like [3, 48, 320]","If the op is missing, add it: - RecResizeImg: { image_shape: [3, 48, 320], max_text_length: 25 }","Prefer rec model assets provided by this paddleocr-js release, which ship a compatible config","If you re-exported the model, copy the PreProcess section from the original PaddleOCR config"],"exampleFix":"# before (inference.yml)\nPreProcess:\n  transform_ops:\n    - NormalizeImage: { scale: 1./255, mean: [0.485,0.456,0.406], std: [0.229,0.224,0.225] }\n\n# after\nPreProcess:\n  transform_ops:\n    - RecResizeImg:\n        image_shape: [3, 48, 320]\n        max_text_length: 25\n    - NormalizeImage: { scale: 1./255, mean: [0.485,0.456,0.406], std: [0.229,0.224,0.225] }","handlingStrategy":"validation","validationCode":"import { parse } from \"yaml\";\nconst doc = parse(recInferenceYmlText) as any;\nconst ops = doc?.PreProcess?.transform_ops ?? [];\nconst resize = ops.find((o: any) => o.RecResizeImg)?.RecResizeImg;\nif (!Array.isArray(resize?.image_shape) || resize.image_shape.length < 3) {\n  throw new Error(\"rec inference.yml lacks RecResizeImg.image_shape — fix before loading\");\n}","typeGuard":"function hasRecResizeShape(doc: unknown): boolean {\n  const ops = (doc as any)?.PreProcess?.transform_ops;\n  return Array.isArray(ops) && ops.some((o: any) => Array.isArray(o?.RecResizeImg?.image_shape) && o.RecResizeImg.image_shape.length >= 3);\n}","tryCatchPattern":"try { parseRecModelConfigText(ymlText); } catch (e) {\n  if (e instanceof Error && /RecResizeImg\\.image_shape/.test(e.message)) {\n    // patch the YAML (add RecResizeImg.image_shape: [3,48,320]) or use bundled asset\n  } else throw e;\n}","preventionTips":["Validate any custom rec model's inference.yml for RecResizeImg.image_shape before deployment","Keep the original PaddleOCR config next to re-exported models and diff PreProcess sections","Prefer assets shipped with the package unless a custom model is required"],"tags":["paddleocr","recognition","config","yaml","model-asset"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}