WZMIAOMIAO/deep-learning-for-image-processing · error · Exception

%s does not exist

Error message

%s does not exist

What it means

YOLOv3 LoadImagesAndLabels __init__ reads a text file of image paths; if os.path.isfile(path) is False it raises Exception('%s does not exist' % path). The path given for train/val data listing does not point to an existing file.

Source

Thrown at pytorch_object_detection/yolov3_spp/build_utils/datasets.py:71

                 # 当为训练集时,设置的是训练过程中(开启多尺度)的最大尺寸
                 # 当为验证集时,设置的是最终使用的网络大小
                 img_size=416,
                 batch_size=16,
                 augment=False,  # 训练集设置为True(augment_hsv),验证集设置为False
                 hyp=None,  # 超参数字典,其中包含图像增强会使用到的超参数
                 rect=False,  # 是否使用rectangular training
                 cache_images=False,  # 是否缓存图片到内存中
                 single_cls=False, pad=0.0, rank=-1):

        try:
            path = str(Path(path))
            # parent = str(Path(path).parent) + os.sep
            if os.path.isfile(path):  # file
                # 读取对应my_train/val_data.txt文件,读取每一行的图片路劲信息
                with open(path, "r") as f:
                    f = f.read().splitlines()
            else:
                raise Exception("%s does not exist" % path)

            # 检查每张图片后缀格式是否在支持的列表中,保存支持的图像路径
            # img_formats = ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.dng']
            self.img_files = [x for x in f if os.path.splitext(x)[-1].lower() in img_formats]
            self.img_files.sort()  # 防止不同系统排序不同,导致shape文件出现差异
        except Exception as e:
            raise FileNotFoundError("Error loading data from {}. {}".format(path, e))

        # 如果图片列表中没有图片,则报错
        n = len(self.img_files)
        assert n > 0, "No images found in %s. See %s" % (path, help_url)

        # batch index
        # 将数据划分到一个个batch中
        bi = np.floor(np.arange(n) / batch_size).astype(np.int)
        # 记录数据集划分后的总batch数
        nb = bi[-1] + 1  # number of batches

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Generate the data listing .txt file (split_data.py) before training
  2. Use an absolute path or verify path exists with os.path.isfile(path)
  3. Run the training command from the project root so relative paths resolve correctly

Example fix

// before
parser.add_argument('--data-txt', default='data/my_train.txt')
// after
import os
txt = 'data/my_train.txt'
assert os.path.isfile(txt), f'{txt} not found - run split_data.py first'
parser.add_argument('--data-txt', default=txt)
Defensive patterns

Strategy: validation

Validate before calling

import os
txt = args.data_txt
if not os.path.isfile(txt):
    raise FileNotFoundError(f'{txt} missing; generate it with split_data.py')

Try / catch

try:
    dataset = LoadImagesAndLabels(txt, img_size=img_size)
except Exception as e:
    if 'does not exist' in str(e):
        raise FileNotFoundError(f'Generate the data listing first: {txt}') from e
    raise

Prevention

When it happens

Trigger: Instantiating LoadImagesAndLabels with a path to my_train.txt / my_val.txt that does not exist on disk (typo, wrong working directory, file never generated).

Common situations: Forgetting to run the split-data script that writes the .txt listing; relative path resolved from a different CWD when training from another directory; path points to a directory instead of a file.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30). Data as JSON: /api/errors/373bb0c9cab2afd1. Report an issue: GitHub.