ultralytics/yolov5 · error · ValueError
Invalid model path {w}. Provide model directory or a .pdipar
Error message
Invalid model path {w}. Provide model directory or a .pdiparams file. What it means
In the PaddlePaddle branch of DetectMultiBackend, ValueError is raised when the weight path is neither a directory nor a file with the .pdiparams suffix. The loader expects either the export directory containing model.json + *.pdiparams, or the .pdiparams file itself (it then looks for a sibling model.json). Any other shape (e.g. a bare .json, a .pdmodel, or a random file) hits this branch.
Source
Thrown at models/common.py:654
meta = ast.literal_eval(model.read(meta_file).decode("utf-8"))
stride, names = int(meta["stride"]), meta["names"]
elif tfjs: # TF.js
raise NotImplementedError("ERROR: YOLOv5 TF.js inference is not supported")
# PaddlePaddle
elif paddle:
LOGGER.info(f"Loading {w} for PaddlePaddle inference...")
check_requirements("paddlepaddle-gpu" if cuda else "paddlepaddle>=3.0.0")
import paddle.inference as pdi
w = Path(w)
if w.is_dir():
model_file = next(w.rglob("*.json"), None)
params_file = next(w.rglob("*.pdiparams"), None)
elif w.suffix == ".pdiparams":
model_file = w.with_name("model.json")
params_file = w
else:
raise ValueError(f"Invalid model path {w}. Provide model directory or a .pdiparams file.")
if not (model_file and params_file and model_file.is_file() and params_file.is_file()):
raise FileNotFoundError(f"Model files not found in {w}. Both .json and .pdiparams files are required.")
config = pdi.Config(str(model_file), str(params_file))
if cuda:
config.enable_use_gpu(memory_pool_init_size_mb=2048, device_id=0)
config.disable_mkldnn() # disable MKL-DNN for PIR compatibility
predictor = pdi.create_predictor(config)
input_handle = predictor.get_input_handle(predictor.get_input_names()[0])
output_names = predictor.get_output_names()
elif triton: # NVIDIA Triton Inference Server
LOGGER.info(f"Using {w} as Triton Inference Server...")
check_requirements("tritonclient[all]")
from utils.triton import TritonRemoteModel
model = TritonRemoteModel(url=w)View on GitHub (pinned to 20d1d78a08)
Solutions
- Point at the export directory produced by export.py --include paddle, which contains model.json and model.pdiparams.
- Or point directly at the .pdiparams file; the loader pairs it with a sibling model.json automatically.
- Do not pass .pdmodel or .json paths; they are not accepted inputs.
Example fix
# before
model = DetectMultiBackend('model.json')
# after
model = DetectMultiBackend('yolov5s_paddle_model/') # dir with model.json + model.pdiparams Defensive patterns
Strategy: type-guard
Validate before calling
from pathlib import Path
def valid_paddle_path(w) -> bool:
p = Path(w)
return p.is_dir() or p.suffix == '.pdiparams' Type guard
from pathlib import Path
def is_paddle_loadable(w: str) -> bool:
"""True if DetectMultiBackend's paddle branch accepts this path shape."""
p = Path(w)
return p.is_dir() or p.suffix == ".pdiparams" Prevention
- Always pass the export.py --include paddle output directory untouched.
- Never rename .pdiparams/model.json files individually.
When it happens
Trigger: Passing DetectMultiBackend('model.json') or a .pdmodel file; passing the directory of a Paddle *training* checkpoint rather than a Paddle Inference export; a typo'd path with a wrong extension.
Common situations: Converting models with paddle tools and handing DetectMultiBackend the wrong artifact of the set; copying only some files out of the export directory and renaming them.
Related errors
- Model files not found in {w}. Both .json and .pdiparams file
- ERROR: {w} is not a supported format
- ERROR: YOLOv5 TF.js inference is not supported
- Source path '{source}' does not exist
- TensorRT engine deserialization failed. Re-export the engine
AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15).
Data as JSON: /api/errors/71579545726e5c00.
Report an issue: GitHub.