{"record":{"id":"ab0245e0673e4d8c","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"vocdevkit-dose-not-in-path-ab0245","errorCode":null,"errorMessage":"VOCdevkit dose not in path:'{}'.","messagePattern":"VOCdevkit dose not in path:'(.+?)'\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"pytorch_object_detection/faster_rcnn/train_res50_fpn.py","lineNumber":59,"sourceCode":"\n\ndef main(args):\n    device = torch.device(args.device if torch.cuda.is_available() else \"cpu\")\n    print(\"Using {} device training.\".format(device.type))\n\n    # 用来保存coco_info的文件\n    results_file = \"results{}.txt\".format(datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\"))\n\n    data_transform = {\n        \"train\": transforms.Compose([transforms.ToTensor(),\n                                     transforms.RandomHorizontalFlip(0.5)]),\n        \"val\": transforms.Compose([transforms.ToTensor()])\n    }\n\n    VOC_root = args.data_path\n    # check voc root\n    if os.path.exists(os.path.join(VOC_root, \"VOCdevkit\")) is False:\n        raise FileNotFoundError(\"VOCdevkit dose not in path:'{}'.\".format(VOC_root))\n\n    # load train data set\n    # VOCdevkit -> VOC2012 -> ImageSets -> Main -> train.txt\n    train_dataset = VOCDataSet(VOC_root, \"2012\", data_transform[\"train\"], \"train.txt\")\n    train_sampler = None\n\n    # 是否按图片相似高宽比采样图片组成batch\n    # 使用的话能够减小训练时所需GPU显存，默认使用\n    if args.aspect_ratio_group_factor >= 0:\n        train_sampler = torch.utils.data.RandomSampler(train_dataset)\n        # 统计所有图像高宽比例在bins区间中的位置索引\n        group_ids = create_aspect_ratio_groups(train_dataset, k=args.aspect_ratio_group_factor)\n        # 每个batch图片从同一高宽比例区间中取\n        train_batch_sampler = GroupedBatchSampler(train_sampler, group_ids, args.batch_size)\n\n    # 注意这里的collate_fn是自定义的，因为读取的数据包括image和targets，不能直接使用默认的方法合成batch\n    batch_size = args.batch_size\n    nw = min([os.cpu_count(), batch_size if batch_size > 1 else 0, 8])  # number of workers","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_object_detection/faster_rcnn/train_res50_fpn.py#L41-L77","documentation":"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.","triggerScenarios":"Running train_res50_fpn.py with --data-path pointing to a directory without the VOCdevkit subfolder, or to VOCdevkit itself instead of its parent.","commonSituations":"Dataset not downloaded/extracted; wrong data-path argument; running from a different working directory so relative paths break.","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"],"exampleFix":"# before\npython train_res50_fpn.py --data-path ./VOCdevkit/VOC2012\n# after\npython train_res50_fpn.py --data-path ./  # ./VOCdevkit exists","handlingStrategy":"validation","validationCode":"import os\nvoc_root = args.data_path\nif not os.path.exists(os.path.join(voc_root, \"VOCdevkit\")):\n    raise SystemExit(f\"VOCdevkit not found under {voc_root}\")","typeGuard":null,"tryCatchPattern":"try:\n    train(args)\nexcept FileNotFoundError as e:\n    if \"VOCdevkit\" in str(e):\n        print(\"Run scripts/download_voc2012.sh first\")\n        sys.exit(1)","preventionTips":["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"],"tags":["python","filenotfound","dataset","environment"],"backgroundTag":"missing-dataset-path","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}