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

VOCdevkit dose not in path:'{}'.

Error message

VOCdevkit dose not in path:'{}'.

What it means

Same FileNotFoundError check as training (index 100), raised in validation.py main(): the --data-path given to validation must contain VOCdevkit. Validation loads VOCDataSet with images and annotations from VOC_root/VOCdevkit/VOC2012, so an absent VOCdevkit aborts before any inference.

Source

Thrown at pytorch_object_detection/retinaNet/validation.py:111

    device = torch.device(parser_data.device if torch.cuda.is_available() else "cpu")
    print("Using {} device training.".format(device.type))

    data_transform = {
        "val": transforms.Compose([transforms.ToTensor()])
    }

    # read class_indict
    label_json_path = './pascal_voc_classes.json'
    assert os.path.exists(label_json_path), "json file {} dose not exist.".format(label_json_path)
    with open(label_json_path, 'r') as f:
        class_dict = json.load(f)

    category_index = {v: k for k, v in class_dict.items()}

    VOC_root = parser_data.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))

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

    # load validation data set
    val_dataset = VOCDataSet(VOC_root, "2012", data_transform["val"], "val.txt")
    val_dataset_loader = torch.utils.data.DataLoader(val_dataset,
                                                     batch_size=batch_size,
                                                     shuffle=False,
                                                     num_workers=nw,
                                                     pin_memory=True,
                                                     collate_fn=val_dataset.collate_fn)

    # create model
    # 注意,这里的norm_layer要和训练脚本中保持一致
    backbone = resnet50_fpn_backbone(norm_layer=torch.nn.BatchNorm2d,

View on GitHub (pinned to 1ec3fe6f37)

Solutions

  1. Point --data-path at the parent directory of VOCdevkit (data_path/VOCdevkit/VOC2012 must exist)
  2. Extract/restore the VOC2012 dataset at the specified path
  3. Use an absolute path to avoid cwd-dependent relative path mistakes

Example fix

// before
python validation.py --data-path ./my_dataset
// after
python validation.py --data-path /data/VOC  # /data/VOC/VOCdevkit/VOC2012 present
Defensive patterns

Strategy: validation

Validate before calling

import os
root = parser_data.data_path
if not os.path.isdir(os.path.join(root, 'VOCdevkit')):
    raise SystemExit(f'--data-path must contain VOCdevkit/, got {root}')

Type guard

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

Try / catch

try:
    main(parser_data)
except FileNotFoundError as e:
    print(f'Dataset root missing: {e}')

Prevention

When it happens

Trigger: Running validation.py with --data-path pointing to a nonexistent folder, to VOCdevkit itself (one level too deep), or to a machine that lacks the extracted VOC2012 dataset.

Common situations: Validating on a different server than training without copying the dataset; changing --data-path to a test placeholder; renaming VOCdevkit directory.

Related errors


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