PaddlePaddle/PaddleOCR · error · ValueError

not find {file_name}.pdiparams in {model_dir}

Error message

not find {file_name}.pdiparams in {model_dir}

What it means

In the non-ONNX branch of create_predictor, Paddle Inference requires both a program file and a parameters file. The code searches model_dir for model.pdiparams or inference.pdiparams; if neither exists it raises this ValueError naming the last candidate checked. Note the message uses the loop variable file_name, so it can misleadingly report 'inference.pdiparams' as missing when model.pdiparams was the intended file. It usually means the model download was incomplete or the directory contains only ONNX/other files.

Source

Thrown at tools/infer/utility.py:251

                sess_options=sess_options,
            )
        inputs = sess.get_inputs()
        return (
            sess,
            inputs[0] if len(inputs) == 1 else [vo.name for vo in inputs],
            None,
            None,
        )

    else:
        file_names = ["model", "inference"]
        for file_name in file_names:
            params_file_path = f"{model_dir}/{file_name}.pdiparams"
            if os.path.exists(params_file_path):
                break

        if not os.path.exists(params_file_path):
            raise ValueError(f"not find {file_name}.pdiparams in {model_dir}")

        if not (
            os.path.exists(f"{model_dir}/{file_name}.pdmodel")
            or os.path.exists(f"{model_dir}/{file_name}.json")
        ):
            raise ValueError(
                f"neither {file_name}.json nor {file_name}.pdmodel was found in {model_dir}."
            )

        if os.path.exists(f"{model_dir}/{file_name}.json"):
            model_file_path = f"{model_dir}/{file_name}.json"
        else:
            model_file_path = f"{model_dir}/{file_name}.pdmodel"

        config = inference.Config(model_file_path, params_file_path)

        if hasattr(args, "precision"):
            if args.precision == "fp16" and args.use_tensorrt:

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. List the directory: ls <model_dir> — confirm either model.pdiparams or inference.pdiparams is present
  2. Re-download and fully extract the model tar ball; point --*_model_dir at the directory that directly contains the .pdmodel/.pdiparams pair
  3. If you only have checkpoints, export an inference model first using tools/export_model.py

Example fix

# before
--det_model_dir=./inference  # contains det_db_infer/ subdir only

# after
tar -xf det_mv3_db.tar -C ./inference  # fully extracted
--det_model_dir=./inference/det_db_infer  # holds inference.pdmodel + inference.pdiparams
Defensive patterns

Strategy: validation

Validate before calling

import os
def has_params(d):
    return os.path.exists(os.path.join(d, 'model.pdiparams')) or os.path.exists(os.path.join(d, 'inference.pdiparams'))
assert has_params(model_dir), f'{model_dir} lacks model.pdiparams / inference.pdiparams'

Try / catch

try:
    utility.create_predictor(args, mode, logger)
except ValueError as e:
    if '.pdiparams' in str(e):
        raise SystemExit(f'incomplete model dir {model_dir}: re-download or re-export the inference model')
    raise

Prevention

When it happens

Trigger: Passing --det_model_dir/--rec_model_dir (etc.) pointing at a directory lacking both model.pdiparams and inference.pdiparams — empty dir, partial extraction, or a dir holding only .onnx/.pdmodel files.

Common situations: Interrupted or partial tar extraction of a model package; pointing at the parent of the actual model dir (nested extraction like det_infer/det_infer/...); downloading only weights without params; mistakenly using a dir of saved checkpoints (best_accuracy.*) instead of exported inference models.

Related errors


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