PaddlePaddle/PaddleOCR · error · ValueError

only support yaml files for now, got {file_path}

Error message

only support yaml files for now, got {file_path}

What it means

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.

Source

Thrown at tools/infer/utility.py:540

        return np.float64
    elif pd_dtype == inference.DataType.FLOAT32:
        return np.float32
    elif pd_dtype == inference.DataType.INT64:
        return np.int64
    elif pd_dtype == inference.DataType.INT32:
        return np.int32
    elif pd_dtype == inference.DataType.UINT8:
        return np.uint8
    elif pd_dtype == inference.DataType.INT8:
        return np.int8
    else:
        raise TypeError(f"Unsupported data type: {pd_dtype}")


def load_config(file_path):
    _, ext = os.path.splitext(file_path)
    if ext not in [".yml", ".yaml"]:
        raise ValueError(f"only support yaml files for now, got {file_path}")
    with open(file_path, "rb") as file:
        config = yaml.load(file, Loader=yaml.SafeLoader)
    return config


def get_output_tensors(args, mode, predictor):
    output_names = predictor.get_output_names()
    output_tensors = []
    if mode == "rec" and args.rec_algorithm in ["CRNN", "SVTR_LCNet", "SVTR_HGNet"]:
        output_name = "softmax_0.tmp_0"
        if output_name in output_names:
            return [predictor.get_output_handle(output_name)]
        else:
            for output_name in output_names:
                output_tensor = predictor.get_output_handle(output_name)
                output_tensors.append(output_tensor)
    else:
        for output_name in output_names:

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Rename the file to end in .yml or .yaml and pass that path
  2. Filter candidate files before calling: [p for p in paths if p.suffix in ('.yml','.yaml')]
  3. Check for typos in the path — including invisible trailing characters

Example fix

# before
config = utility.load_config('./configs/rec/rec_config.json')  # ValueError

# after
config = utility.load_config('./configs/rec/rec_config.yaml')
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
p = Path(config_path)
assert p.suffix in ('.yml', '.yaml'), f'config must be .yml/.yaml, got {p.suffix or "<none>"}'
config = utility.load_config(str(p))

Type guard

from pathlib import Path

def is_yaml_path(p) -> bool:
    return Path(p).suffix in ('.yml', '.yaml')

Try / catch

try:
    config = utility.load_config(path)
except ValueError as e:
    if 'only support yaml' in str(e):
        path = str(Path(path).with_suffix('.yaml'))
        config = utility.load_config(path)
    raise

Prevention

When it happens

Trigger: Calling utility.load_config('configs/rec/config.txt') or passing a path with trailing whitespace/dot, or a directory path without a file extension.

Common situations: Scripts auto-discovering config files by globbing '*' instead of '*.yml'; Windows paths with mixed separators corrupting the extension check; users renaming configs to .conf.

Related errors


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