PaddlePaddle/PaddleOCR · error · Exception

{} does not exist!

Error message

{} does not exist!

What it means

PGNet (spotted text detection/recognition) dataset loading iterates label lines, joins data_dir with the filename from the label, and requires the resulting path to exist. A missing file raises Exception('{path} does not exist!'); the outer handler logs it and skips the sample (outs = None).

Source

Thrown at ppocr/data/pgnet_dataset.py:90

    def __getitem__(self, idx):
        file_idx = self.data_idx_order_list[idx]
        data_line = self.data_lines[file_idx]
        img_id = 0
        try:
            data_line = data_line.decode("utf-8")
            substr = data_line.strip("\n").split(self.delimiter)
            file_name = substr[0]
            label = substr[1]
            img_path = os.path.join(self.data_dir, file_name)
            if self.mode.lower() == "eval":
                try:
                    img_id = int(data_line.split(".")[0][7:])
                except:
                    img_id = 0
            data = {"img_path": img_path, "label": label, "img_id": img_id}
            if not os.path.exists(img_path):
                raise Exception("{} does not exist!".format(img_path))
            with open(data["img_path"], "rb") as f:
                img = f.read()
                data["image"] = img
            outs = transform(data, self.ops)
        except Exception as e:
            self.logger.error(
                "When parsing line {}, error happened with msg: {}".format(
                    self.data_idx_order_list[idx], e
                )
            )
            outs = None
        if outs is None:
            return self.__getitem__(np.random.randint(self.__len__()))
        return outs

    def __len__(self):
        return len(self.data_idx_order_list)

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Spot-check paths: python -c 'import os; l=open(label).readline().split("\t")[0]; print(os.path.exists(os.path.join(data_dir, l)))'
  2. Correct data_dir in the PGNet yml so joined paths resolve
  3. Re-extract the image archive preserving directory structure, or rewrite the label file to match the actual layout
  4. Normalize separators in label files: line.replace('\\', '/') before use

Example fix

# before (config)
data_dir: ./train_data/pgnet
label_file_list: ./train_data/labels.txt
# after (match actual layout)
data_dir: ./train_data/pgnet/train_images
label_file_list: ./train_data/pgnet/train_labels.txt
Defensive patterns

Strategy: validation

Validate before calling

import os
with open(label_file, encoding='utf-8') as f:
    for k, line in enumerate(f):
        name = line.strip('\r\n').split(delimiter)[0]
        p = name if name.startswith('http') else os.path.join(data_dir, name)
        if not p.startswith('http') and not os.path.exists(p):
            raise SystemExit(f'line {k}: {p} does not exist')

Try / catch

try:
    out = dataset[idx]
except Exception:
    out = None  # dataset already logs and skips; count skips and abort if too many

Prevention

When it happens

Trigger: A label line whose first field (before the delimiter) names an image that is not under data_dir: moved images, wrong data_dir, absolute-vs-relative mismatch, or a Windows/Windows-path label on Linux.

Common situations: Downloading only the label file without the images; unzipping that flattens the directory structure; data_dir typo in the yml; label file using backslashes.

Related errors


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