PaddlePaddle/PaddleOCR · error

RecResizeImg.image_shape is required in rec inference.yml

Error message

RecResizeImg.image_shape is required in rec inference.yml

What it means

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.

Source

Thrown at paddleocr-js/packages/core/src/models/rec.ts:78

export const DEFAULT_REC_RUNTIME_LIMITS = Object.freeze({});

const MAX_REC_WIDTH = 3200;

export const DEFAULT_REC_MODEL_CONFIG: Readonly<RecModelConfig> = Object.freeze({
  ...DEFAULT_REC_MODEL_PARSE_FALLBACKS
});

export function parseRecModelConfigText(text: string): RecModelConfig {
  const parsed = parseInferenceConfigText(text);
  const preProcess = parsed.PreProcess as Record<string, unknown> | undefined;
  const transformOps = preProcess?.transform_ops as Array<Record<string, unknown>> | undefined;
  const resize = getTransformOp(transformOps, "RecResizeImg");
  const postprocess = (parsed.PostProcess || {}) as Record<string, unknown>;
  const baseCharDict = postprocess.character_dict;

  const imageShape = resize?.image_shape as number[] | undefined;
  if (!imageShape || !Array.isArray(imageShape) || imageShape.length < 3) {
    throw new Error("RecResizeImg.image_shape is required in rec inference.yml");
  }

  const charDict =
    Array.isArray(baseCharDict) && baseCharDict.length > 0
      ? [...(baseCharDict as string[]), " "]
      : [...DEFAULT_REC_ALPHANUMERIC_DICT, " "];

  return {
    imageShape,
    charDict
  };
}

interface CreateRecModelArgs {
  ort: OrtModule;
  modelBytes: Uint8Array;
  configText: string;
  backend: string;

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Open the rec model's inference.yml and confirm PreProcess.transform_ops includes RecResizeImg with image_shape like [3, 48, 320]
  2. If the op is missing, add it: - RecResizeImg: { image_shape: [3, 48, 320], max_text_length: 25 }
  3. Prefer rec model assets provided by this paddleocr-js release, which ship a compatible config
  4. If you re-exported the model, copy the PreProcess section from the original PaddleOCR config

Example fix

# before (inference.yml)
PreProcess:
  transform_ops:
    - NormalizeImage: { scale: 1./255, mean: [0.485,0.456,0.406], std: [0.229,0.224,0.225] }

# after
PreProcess:
  transform_ops:
    - RecResizeImg:
        image_shape: [3, 48, 320]
        max_text_length: 25
    - NormalizeImage: { scale: 1./255, mean: [0.485,0.456,0.406], std: [0.229,0.224,0.225] }
Defensive patterns

Strategy: validation

Validate before calling

import { parse } from "yaml";
const doc = parse(recInferenceYmlText) as any;
const ops = doc?.PreProcess?.transform_ops ?? [];
const resize = ops.find((o: any) => o.RecResizeImg)?.RecResizeImg;
if (!Array.isArray(resize?.image_shape) || resize.image_shape.length < 3) {
  throw new Error("rec inference.yml lacks RecResizeImg.image_shape — fix before loading");
}

Type guard

function hasRecResizeShape(doc: unknown): boolean {
  const ops = (doc as any)?.PreProcess?.transform_ops;
  return Array.isArray(ops) && ops.some((o: any) => Array.isArray(o?.RecResizeImg?.image_shape) && o.RecResizeImg.image_shape.length >= 3);
}

Try / catch

try { parseRecModelConfigText(ymlText); } catch (e) {
  if (e instanceof Error && /RecResizeImg\.image_shape/.test(e.message)) {
    // patch the YAML (add RecResizeImg.image_shape: [3,48,320]) or use bundled asset
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/891b56f09195e838. Report an issue: GitHub.