WZMIAOMIAO/deep-learning-for-image-processing · error · FileNotFoundError
VOCdevkit dose not in path:'{}'.
Error message
VOCdevkit dose not in path:'{}'. What it means
train_res50_fpn.py validates that `<args.data_path>/VOCdevkit` exists before constructing the VOC dataset; otherwise it raises FileNotFoundError. Same root-check pattern as the other training scripts.
Source
Thrown at pytorch_object_detection/faster_rcnn/train_res50_fpn.py:59
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 workersView on GitHub (pinned to 1ec3fe6f37)
Solutions
- Extract the VOC2012 dataset so `<data_path>/VOCdevkit` exists
- Pass the parent directory containing VOCdevkit as --data-path
- Confirm the layout VOCdevkit/VOC2012/ImageSets/Main/train.txt exists
Example fix
# before python train_res50_fpn.py --data-path ./VOCdevkit/VOC2012 # after python train_res50_fpn.py --data-path ./ # ./VOCdevkit exists
Defensive patterns
Strategy: validation
Validate before calling
import os
voc_root = args.data_path
if not os.path.exists(os.path.join(voc_root, "VOCdevkit")):
raise SystemExit(f"VOCdevkit not found under {voc_root}") Try / catch
try:
train(args)
except FileNotFoundError as e:
if "VOCdevkit" in str(e):
print("Run scripts/download_voc2012.sh first")
sys.exit(1) Prevention
- Extract VOC2012 to the expected location before training
- Pass the directory containing VOCdevkit (its parent), not VOCdevkit itself
- Keep a setup script that verifies dataset layout before training
When it happens
Trigger: Running train_res50_fpn.py with --data-path pointing to a directory without the VOCdevkit subfolder, or to VOCdevkit itself instead of its parent.
Common situations: Dataset not downloaded/extracted; wrong data-path argument; running from a different working directory so relative paths break.
Related errors
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
- VOCdevkit dose not in path:'{}'.
- image: {} isn't RGB mode.
- not find GPU device for training.
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/ab0245e0673e4d8c.
Report an issue: GitHub.