ultralytics/yolov5 · error · FileNotFoundError

Model files not found in {w}. Both .json and .pdiparams file

Error message

Model files not found in {w}. Both .json and .pdiparams files are required.

What it means

The PaddlePaddle branch raises FileNotFoundError when the candidate model.json / .pdiparams pair could not both be located and verified with is_file(). This is distinct from the ValueError case: the path shape was right (a directory, or a .pdiparams file) but the files inside/next to it are missing — e.g. an empty directory, an incomplete copy, or model.json named differently.

Source

Thrown at models/common.py:657

            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)
            nhwc = model.runtime.startswith("tensorflow")
        else:
            raise NotImplementedError(f"ERROR: {w} is not a supported format")

View on GitHub (pinned to 20d1d78a08)

Solutions

  1. Re-export with the repo's exporter: python export.py --weights yolov5s.pt --include paddle, then use the produced directory.
  2. Verify both required files exist: the directory must contain a *.json and a *.pdiparams (or the .pdiparams must sit next to model.json).
  3. If filenames were changed, rename them back to model.json / model.pdiparams.

Example fix

# before
model = DetectMultiBackend('paddle_out/')  # missing model.json

# after
# ensure: paddle_out/model.json and paddle_out/model.pdiparams both exist
model = DetectMultiBackend('paddle_out/')
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def paddle_files_complete(w) -> bool:
    p = Path(w)
    if p.is_dir():
        return any(p.rglob('*.json')) and any(p.rglob('*.pdiparams'))
    if p.suffix == '.pdiparams':
        return p.with_name('model.json').is_file()
    return False

Try / catch

try:
    model = DetectMultiBackend(paddle_dir)
except FileNotFoundError as e:
    if 'Both .json and .pdiparams' in str(e):
        reexport_paddle()  # python export.py --include paddle

Prevention

When it happens

Trigger: Passing an export directory that lacks model.json (renamed, deleted, or never generated); passing a .pdiparams file whose sibling model.json is absent; rglob in a directory that contains .pdiparams but no .json at the top level searched.

Common situations: Incomplete rsync/docker COPY of the paddle export; exporting with an older export.py that produced different filenames; manual file reorganization breaking the required sibling relationship.

Related errors


AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15). Data as JSON: /api/errors/cde4a6b973758064. Report an issue: GitHub.