{"record":{"id":"30a133c781eccf9d","repo":"PaddlePaddle/PaddleOCR","slug":"only-support-yaml-files-for-now-got-file-path","errorCode":null,"errorMessage":"only support yaml files for now, got {file_path}","messagePattern":"only support yaml files for now, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/infer/utility.py","lineNumber":540,"sourceCode":"        return np.float64\n    elif pd_dtype == inference.DataType.FLOAT32:\n        return np.float32\n    elif pd_dtype == inference.DataType.INT64:\n        return np.int64\n    elif pd_dtype == inference.DataType.INT32:\n        return np.int32\n    elif pd_dtype == inference.DataType.UINT8:\n        return np.uint8\n    elif pd_dtype == inference.DataType.INT8:\n        return np.int8\n    else:\n        raise TypeError(f\"Unsupported data type: {pd_dtype}\")\n\n\ndef load_config(file_path):\n    _, ext = os.path.splitext(file_path)\n    if ext not in [\".yml\", \".yaml\"]:\n        raise ValueError(f\"only support yaml files for now, got {file_path}\")\n    with open(file_path, \"rb\") as file:\n        config = yaml.load(file, Loader=yaml.SafeLoader)\n    return config\n\n\ndef get_output_tensors(args, mode, predictor):\n    output_names = predictor.get_output_names()\n    output_tensors = []\n    if mode == \"rec\" and args.rec_algorithm in [\"CRNN\", \"SVTR_LCNet\", \"SVTR_HGNet\"]:\n        output_name = \"softmax_0.tmp_0\"\n        if output_name in output_names:\n            return [predictor.get_output_handle(output_name)]\n        else:\n            for output_name in output_names:\n                output_tensor = predictor.get_output_handle(output_name)\n                output_tensors.append(output_tensor)\n    else:\n        for output_name in output_names:","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/tools/infer/utility.py#L522-L558","documentation":"utility.load_config parses model metadata files (inference.yml) with yaml.safe_load, but first rejects any path whose extension is not .yml or .yaml. This ValueError exists to fail fast on obviously wrong inputs (e.g. passing a .txt, .json, or extensionless path) before yaml parsing produces confusing errors. The PaddleOCR model gates (predict_cls/det/rec/sr/e2e) call it on <model_dir>/inference.yml, so in practice this fires when callers invoke load_config directly with a bad path.","triggerScenarios":"Calling utility.load_config('configs/rec/config.txt') or passing a path with trailing whitespace/dot, or a directory path without a file extension.","commonSituations":"Scripts auto-discovering config files by globbing '*' instead of '*.yml'; Windows paths with mixed separators corrupting the extension check; users renaming configs to .conf.","solutions":["Rename the file to end in .yml or .yaml and pass that path","Filter candidate files before calling: [p for p in paths if p.suffix in ('.yml','.yaml')]","Check for typos in the path — including invisible trailing characters"],"exampleFix":"# before\nconfig = utility.load_config('./configs/rec/rec_config.json')  # ValueError\n\n# after\nconfig = utility.load_config('./configs/rec/rec_config.yaml')","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(config_path)\nassert p.suffix in ('.yml', '.yaml'), f'config must be .yml/.yaml, got {p.suffix or \"<none>\"}'\nconfig = utility.load_config(str(p))","typeGuard":"from pathlib import Path\n\ndef is_yaml_path(p) -> bool:\n    return Path(p).suffix in ('.yml', '.yaml')","tryCatchPattern":"try:\n    config = utility.load_config(path)\nexcept ValueError as e:\n    if 'only support yaml' in str(e):\n        path = str(Path(path).with_suffix('.yaml'))\n        config = utility.load_config(path)\n    raise","preventionTips":["Glob configs with '*.yml'/'*.yaml' patterns instead of '*'","Normalize config paths through pathlib and validate suffixes at load boundaries"],"tags":["yaml","file-extension","config","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}