PaddlePaddle/PaddleOCR · error · ValueError
neither {file_name}.json nor {file_name}.pdmodel was found i
Error message
neither {file_name}.json nor {file_name}.pdmodel was found in {model_dir}. What it means
Companion check to the .pdiparams gate: after finding a params file (model.* or inference.*), create_predictor requires the matching program file — either <name>.pdmodel or <name>.json (the new Paddle 3 serialized format) — in the same directory. Its absence raises this ValueError, meaning the model directory is half-populated (weights without the graph).
Source
Thrown at tools/infer/utility.py:257
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:
precision = inference.PrecisionType.Half
elif args.precision == "int8":
precision = inference.PrecisionType.Int8
else:
precision = inference.PrecisionType.Float32
else:View on GitHub (pinned to 2661c7c0ef)
Solutions
- Check the directory for the matching prefix: if inference.pdiparams exists, you need inference.pdmodel or inference.json
- Re-export the inference model with tools/export_model.py
- Keep the prefix consistent — do not rename model.pdiparams to inference.pdiparams without renaming the program file too
Example fix
# before ls ./inference/rec # inference.pdiparams inference.pdiparams.info (no program file) -> ValueError # after python tools/export_model.py -c configs/rec/PP-OCRv4/rec_PP-OCRv4_mobile.yml \ -o Global.pretrained_model=./pretrain_models/rec_mobile \ Global.save_inference_dir=./inference/rec
Defensive patterns
Strategy: validation
Validate before calling
import os
def valid_infer_dir(d):
for p in ('model', 'inference'):
if os.path.exists(f'{d}/{p}.pdiparams'):
return os.path.exists(f'{d}/{p}.pdmodel') or os.path.exists(f'{d}/{p}.json')
return False
assert valid_infer_dir(model_dir), f'{model_dir} has params but no .pdmodel/.json program file' Try / catch
try:
utility.create_predictor(args, mode, logger)
except ValueError as e:
if 'pdmodel' in str(e) or 'json' in str(e):
raise SystemExit(f'{model_dir}: re-export with tools/export_model.py — program file missing')
raise Prevention
- Always move model files as complete triples (program + params + info) using archive tools, never file-by-file
- Keep the file prefix consistent within a model directory
When it happens
Trigger: A model dir containing inference.pdiparams but neither inference.pdmodel nor inference.json — e.g. weights copied without the program file, or an incomplete export.
Common situations: Manual copying between machines dropping the .pdmodel; export_model.py interrupted mid-write; mixing file naming (model.* vs inference.*) so params and program use different prefixes.
Related errors
- not find {file_name}.pdiparams in {model_dir}
- ${modelRole} in inference.yml must define model_name.
- ${modelRole} in inference.yml declares model_name "${declare
- The `{mask_name}` should be specified for {len(self.layers)}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/5497937717bcbcb5.
Report an issue: GitHub.