PaddlePaddle/PaddleOCR · error · ValueError

The file {label_dir} does not exist!

Error message

The file {label_dir} does not exist!

What it means

convert_label in tools/end2end/convert_ppocr_label.py validates that the given label file path exists before opening it, and raises ValueError otherwise. It is a plain pre-flight filesystem check (the function would otherwise fail with a less clear FileNotFoundError). Note it is called with a file path despite the parameter name label_dir. The subsequent assert label_dir != save_dir is a separate guard against overwriting outputs.

Source

Thrown at tools/end2end/convert_ppocr_label.py:29

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import json
import os


def poly_to_string(poly):
    if len(poly.shape) > 1:
        poly = np.array(poly).flatten()

    string = "\t".join(str(i) for i in poly)
    return string


def convert_label(label_dir, mode="gt", save_dir="./save_results/"):
    if not os.path.exists(label_dir):
        raise ValueError(f"The file {label_dir} does not exist!")

    assert label_dir != save_dir, "hahahhaha"

    label_file = open(label_dir, "r")
    data = label_file.readlines()

    gt_dict = {}

    for line in data:
        try:
            tmp = line.split("\t")
            assert len(tmp) == 2, ""
        except:
            tmp = line.strip().split("    ")

        gt_lists = []

        if tmp[0].split("/")[0] is not None:

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Check the path exists before running: ls <label_path>, fix typos or use an absolute path
  2. If labels come from predict_system/evaluation output, run that step first so the file is produced
  3. Run from the repo root or pass absolute paths so relative resolution is deterministic

Example fix

# before
python tools/end2end/convert_ppocr_label.py --label_path=./out/label.txt
# ValueError: The file ./out/label.txt does not exist!

# after
python tools/end2end/convert_ppocr_label.py --label_path=$(pwd)/out/word_1.txt/label.txt
Defensive patterns

Strategy: validation

Validate before calling

import os
if not os.path.isfile(label_path):
    raise SystemExit(f'label file missing: {label_path} — run the prediction step first')

Try / catch

try:
    convert_label(label_dir=label_path, mode='gt', save_dir=out_dir)
except ValueError as e:
    if 'does not exist' in str(e):
        # regenerate labels or fix the path, then retry once
        ...
    raise

Prevention

When it happens

Trigger: Running tools/end2end/convert_ppocr_label.py with a --label_path pointing at a nonexistent file (typo, wrong directory, or labels not yet generated by the end2end evaluation).

Common situations: After running end2end eval, the predicted-label file lands in a different directory than passed on the command line; CI running from a different working directory with relative paths; typo in the filename.

Related errors


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