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

VOCdevkit dose not in path:'{}'.

Error message

VOCdevkit dose not in path:'{}'.

What it means

The script checks that the configured data root (--data-path) actually contains a 'VOCdevkit' subdirectory before constructing VOCDataSet instances. If os.path.join(VOC_root, 'VOCdevkit') does not exist, it raises FileNotFoundError early with the offending path. This guards against training on a wrong/empty dataset root that would otherwise fail deep inside the dataset loader.

Source

Thrown at pytorch_object_detection/faster_rcnn/change_backbone_with_fpn.py:84


def main(args):
    device = torch.device(args.device if torch.cuda.is_available() else "cpu")
    print("Using {} device training.".format(device.type))

    # 用来保存coco_info的文件
    results_file = "results{}.txt".format(datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))

    data_transform = {
        "train": transforms.Compose([transforms.ToTensor(),
                                     transforms.RandomHorizontalFlip(0.5)]),
        "val": transforms.Compose([transforms.ToTensor()])
    }

    VOC_root = args.data_path
    # check voc root
    if os.path.exists(os.path.join(VOC_root, "VOCdevkit")) is False:
        raise FileNotFoundError("VOCdevkit dose not in path:'{}'.".format(VOC_root))

    # load train data set
    # VOCdevkit -> VOC2012 -> ImageSets -> Main -> train.txt
    train_dataset = VOCDataSet(VOC_root, "2012", data_transform["train"], "train.txt")
    train_sampler = None

    # 是否按图片相似高宽比采样图片组成batch
    # 使用的话能够减小训练时所需GPU显存,默认使用
    if args.aspect_ratio_group_factor >= 0:
        train_sampler = torch.utils.data.RandomSampler(train_dataset)
        # 统计所有图像高宽比例在bins区间中的位置索引
        group_ids = create_aspect_ratio_groups(train_dataset, k=args.aspect_ratio_group_factor)
        # 每个batch图片从同一高宽比例区间中取
        train_batch_sampler = GroupedBatchSampler(train_sampler, group_ids, args.batch_size)

    # 注意这里的collate_fn是自定义的,因为读取的数据包括image和targets,不能直接使用默认的方法合成batch
    batch_size = args.batch_size
    nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8])  # number of workers

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Set --data-path to the directory that directly contains VOCdevkit (the parent of VOCdevkit).
  2. If the dataset is still archived, extract it so that <data-path>/VOCdevkit/VOC2012 exists.
  3. Verify with a shell check: ls <data-path>/VOCdevkit/VOC2012/ImageSets/Main/train.txt.
  4. If using a custom dataset, create the expected VOCdevkit/VOC2012 directory structure or modify the check.
  5. Pass an absolute path to rule out working-directory mismatch.

Example fix

# before
python change_backbone_with_fpn.py --data-path ./VOCdevkit
# after
python change_backbone_with_fpn.py --data-path .   # ./VOCdevkit must exist here
Defensive patterns

Strategy: validation

Validate before calling

import os
voc_root = args.data_path
assert os.path.isdir(os.path.join(voc_root, 'VOCdevkit', 'VOC2012')), f"VOCdevkit missing under {voc_root}"

Type guard

def is_valid_voc_root(path: str) -> bool:
    return os.path.isdir(os.path.join(path, 'VOCdevkit', 'VOC2012'))

Try / catch

try:
    main(args)
except FileNotFoundError as e:
    print(f'Bad --data-path: {e}. Point it at the parent of VOCdevkit.')
    sys.exit(2)

Prevention

When it happens

Trigger: Running train.py or change_backbone_with_fpn.py with --data-path pointing to a directory that does not contain a VOCdevkit folder (e.g. pointing to VOCdevkit itself instead of its parent, or an unextracted tar/zip archive).

Common situations: Passing the VOCdevkit directory instead of its parent, forgetting to extract VOC2012.tar.gz, using a different dataset layout (COCO, custom), or a typo/relative path resolved from the wrong working directory.

Related errors


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